I’ve got a checkboxlist with a variable amount of checkboxes, and I’m doing something like it :
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int j = 0; j < CheckBoxList1.Items.Count; j++)
{
//LabelTest.Text = "Something"; It works here
if (CheckBoxList1.Items[j].Selected)
{
//LabelTest.Text = "Something 2"; It doesn't work here
TextBoxTest.Text = CheckBoxList1.Items[j].Text;
LabelTest.Text = CheckBoxList1.Items[j].Value;
}
}
}
When I check a box, the "Something" is displaying on my page, but the rest isn’t.
I tried to write my "if" like it too :
if (!CheckBoxList1.Items[j].Selected)
And doing like so, when I check a box, my TextBoxTest displays "106", which is the total number of checkboxes I have, but not the number of the checked box.
My CheckBoxList1 has a true autopostback.
The issue is with the way you add items to your CheckBoxList. You provided the code for that in another topic. What you should do is to enclose that code inside this:
Otherwise, you recreate the list on every postback with the default values of false for the Selected property.