Checkbox Question 2

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?
 
B

bruce barker

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)
 
E

Elliot

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)
 
S

Stan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top