I’m populating a CheckBoxList from database table. As per requirement, all the values should be unchecked be default. Even though I have written code to do the same, first value always is checked, and I can’t figure out why. Here’s the code:
for (int i = CheckBoxList1.Items.Count - 1; i >= 0; i--)
CheckBoxList1.Items.RemoveAt(i);
while (rd.Read())
{
System.Web.UI.WebControls.ListItem item = new ListItem(Convert.ToString(rd["FullName"]), Convert.ToString(rd["ContactID"]));
CheckBoxList1.Items.Add(item);
}
con.Close();
for (int i = CheckBoxList1.Items.Count - 1; i >= 0; i--)
CheckBoxList1.Items[i].Selected = false;
Once the page is posted back, only then all the values are unchecked.
Any help and suggestions are most welcome, thank you.
This was happening because of UpdatePanel. Once I removed that, code started working without any problems.