Click to See Complete Forum and Search --> : CheckBoxList always returns Checked=false


WhelanKerry
January 13th, 2003, 10:32 AM
Hi,

I am struggling with the CheckBoxList control. When I add items to the CheckBoxList control at design time and select some of the boxes at runtime, the selected boxes return Checked=true and I can deal with them as I wish. If I add items to the CheckBoxList programmatically at runtime and then use the same code to access the Checked attribute, all boxes return checked=false.


I use a dataReader to bind the values and names to the CheckBoxList:-

CheckBoxList1.DataSource=dataReader;
CheckBoxList1.DataBind();

The following code is used to find which boxes are selected:-

foreach(ListItem li in CheckBoxList1.Items)
{
if(li.Selected==true)
{
//code here
}
}

I have just read that the dynamically created list object does not exist when page is posted back but I do not know how to get around this.


Any help would be greatly appreciated.

Thankyou,

Kerry Whelan