How to get selected values from dynamically generated CheckBoxList? (ASP.NET)

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How to get selected values from dynamically generated CheckBoxList? (ASP.NET)

Hi,
I am generating the CheckBoxList control in Run-Time. I dont know
how to get the selected check box values from dynamically generated checkBoxList.
(I know how to select the values from CheckBoxList if it is desined at runtime)
I tried to use FindControl method but FindControl method returns NULL.

TableRow tRowMach = new TableRow();
Table2.Rows.Add(tRowMech);
TableCell tCellMech = new TableCell();
tRowMech.Cells.Add(tCellMech);
// then the CheckBoxList Control is added in the table cell
tCellMach.Controls.Add(ChkMachines);

I put the above code in loop.

The CheckBoxLists are generated with out any problem. But I want to know
,How to access the selected checkbox values from the dynamically generated
CheckBoxList?
If any one knows Help me to solve this.

Re: How to get selected values from dynamically generated CheckBoxList? (ASP.NET)

I assume the code below is contained in an "if not ispostback"...

For some odd reason you can't dynamically create controls and have them persist
to postback, there may be a way, but I don't know it.. If you take it out
of the "if not ispostback" it will persist and strangely enough maintain
it's state..

Anyone found a solution?

I to am having this problem.

Currently I have been able to add/get response values for almost every contorl that isn't multi selected (textbox, checkbox, radio button, combobox) but not checkboxlist and listbox. When I loop through the form responses I do not get anything returned.

since you are adding the checkboxlist control dynamically, it will not be persisted on postbacks. If you want the values which are selected in the checkbox list, store the selected value in hiddenfields, create the checkboxlist as done before and select the values based on the values stored in the hidden field.