how to get checked or unchecked in checkbox list

2.3k Views Asked by At

Check box list how to get boolean value of the check box list likewise if checked return true if unchecked return false. i tried using for in selected it return true for all the check box.return boolean value based on checked and unchecked

<asp:CheckBoxList ID="ChkPermission" runat="server" 
                onselectedindexchanged="ChkPermission_SelectedIndexChanged" 
                style="text-align: left">
                        <asp:ListItem>Access</asp:ListItem>
                        <asp:ListItem>Add</asp:ListItem>
                        <asp:ListItem>Edit</asp:ListItem>
                        <asp:ListItem>Delete</asp:ListItem>
                        <asp:ListItem>Print</asp:ListItem>
                        <asp:ListItem>Export</asp:ListItem>
                    </asp:CheckBoxList>
1

There are 1 best solutions below

1
On

I have edited this and posted answer in C# to suit @maccettura. I found this bit of code from here How can I get the CheckBoxList selected values, what I have doesn't seem to work C#.NET/VisualWebPart. There are a few different kind of examples on this link if this code below doesn't work for you.

 protected void YrChkBox_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem listItem in YrChkBox.Items)
{
if (listItem.Selected)
{ 
   //do some work 
}
else 
{ 
  //do something else 
}
}}