I have a page with a dropdownlist, a checkboxlist and a button.
On selection of the dropdownlist the page posts back and the checkboxlist is bound like this example:
private void ddlType_selectedIndexChanged (object sender, EventArgs e)
{
cblMyList.Items.Add ("Item1", "Value1");
cblMyList.Items.Add ("Item2, "Value2");
}
Now with my button click I am retrieving the checkboxlist items. For some reason they aren’t retaining their selected states. All of the items are set to false.
It looks like checkboxlists can only be bound from within Page_Init… If this is true is there an alternative way to bind a checkboxlist like I am doing?
This is a known issue. In your page before you do your post, have a javascript function iterate through your checkboxlist and for each one which has .checked == true call .selected = true on them.