Click to See Complete Forum and Search --> : How to get selected values from dynamically generated CheckBoxList? (ASP.NET)


sugunsg
December 26th, 2002, 11:15 PM
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.

Look the code to generate the CheckBoxList in Run Time.

In Code behind...

CheckBoxList ChkMachines = new CheckBoxList();
ChkMachines.ID = "ChkMachines_" + <some variable>
ChkMachines.DataValueField="MECH_ID";
ChkMachines.DataTextField="MECHNAME";
ChkMachines.RepeatColumns=2;
ChkMachines.DataSource = ReaderMech;
ChkMachines.DataBind();
// MECH_ID, MECHNAME is data base fields
// ReaderMech is OleDBDataReader

// tbale Row and cell are generated dynamically

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.

Thanks
sugumar

anupam kant
December 28th, 2002, 12:13 AM
if you want the values after page submission...

I think you can not get selected values from the dynamically created lists as the dynamically created list object does not exist when page is posted back.

alternative solution might be to get the value at client side (thru javascripts) store them in some hidden variable and get the hiddens value at server side.


hope this helps...