when i execute the code i get 4 checkboxs and i checked/selected all 4 checkbox and when i try to debug the code, it does count that i have 4 checkbox but all 4 checkbox is selected=false.
what i am missing in code?
<asp:checkboxlist id="chk" runat="server" ondatabinding="chk_DataBinding"
ondatabound="chk_DataBound">
</asp:checkboxlist>
List<String> roles = new List<string>();
for (int i = 0; i < chk.Items.Count; i++)
{
if (chk.Items[i].Selected)
{
roles.Add(chk.Items[i].Value);
}
}
Your logic is consistent with the basic
CheckBoxListgiven on theListControl.Itemspage, and from personal experience, checking the.Selectedproperty of theListItemshould work fine.Check to make sure you aren’t re-populating the
CheckBoxListbefore you hit the “if checked” logic – if I had to guess, I’d say there’s a good chance you’re losing the list on every postback. The simple solution is don’t call your databinding logic if it’s a postback.