Checkbox Question 2

  • Thread starter Thread starter Elliot
  • Start date Start date
E

Elliot

I use the following way to generate a table with a checkbox each row:

TableRow rowA;
for (int i = 1; i<=10 ; i++)
{
rowA = new TableRow();
cellA = new TableCell();
CheckBox CB = new CheckBox();
cellA.Controls.Add(CB);
row.Cells.Add(cellA);
rowA.Cells.Add(cellA);
}

How can I give those 10 checkboxs different value & how can I obtain them?
 
you should give each checkbox a unique ID. then be sure to recreate the
checkboxs (with the name id's) on postback in the CreateChildControls
method. you also need to add the rows to the table.

-- bruce (sqlwork.com)
 
I see.
Thanks, Bruce.


bruce barker said:
you should give each checkbox a unique ID. then be sure to recreate the
checkboxs (with the name id's) on postback in the CreateChildControls
method. you also need to add the rows to the table.

-- bruce (sqlwork.com)
 
I use the following way to generate a table with a checkbox each row:

            TableRow rowA;
            for (int i = 1; i<=10 ; i++)
            {
                rowA = new TableRow();
                cellA = new TableCell();
                CheckBox CB = new CheckBox();
                cellA.Controls.Add(CB);
                row.Cells.Add(cellA);
                rowA.Cells.Add(cellA);
            }

How can I give those 10 checkboxs different value & how can I obtain them?

You need to run the TableRow construction routine during the Page_Load
event every time (both on the initial page request and during post
back). Thereafter the CheckBox states will be available via the Table
object (presumably declared in page source or globally within the
webform class definition) in any event handler for postback. By
default ViewState is enabled for WebControls and the matching of
CheckBoxes in ViewState with those re-created during Page_load will
occur automatically (ASP.NET uses automatically generated the clientID
for this).

Try it and see

Good luck
 
Back
Top