How to determine the checkedboxlist checked / selected -

when I execute the code, I get 4 checkboxes, and I checked / selected all 4 and when I try to debug the code, it considers that I have 4 checkbox, but all 4 checkboxes selected = false.

What am I missing in the 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);
    }
 }
+3
source share
2 answers

Your logic is consistent with the basic CheckBoxListone indicated on the page ListControl.Items, and from personal experience checking the .Selectedproperty ListItemshould work fine.

, CheckBoxList, " " - , , , . - , .

+2
public string[] CheckboxListSelections(System.Web.UI.WebControls.CheckBoxList list)
{
 ArrayList values = new ArrayList();
 for(int counter = 0; counter < list.Items.Count; counter++)
 {
  if(list.Items[counter].Selected)
  {
   values.Add(list.Items[counter].Value);
  }    
 }
 return (String[]) values.ToArray( typeof( string ) );
}
0

All Articles