-2

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>
sifeee
  • 13
  • 1
  • 1
  • 7
  • 2
    possible duplicate http://stackoverflow.com/questions/18924147/how-to-get-values-of-selected-items-in-checkboxlist-with-foreach-in-asp-net-c – Drew Kennedy Dec 16 '14 at 20:10
  • clear question there no value for the list item.like we use in checkbox.checked condition i need similarly like that in checkboxlist – sifeee Dec 17 '14 at 12:06

1 Answers1

0

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 
}
}}
Community
  • 1
  • 1
user3841709
  • 386
  • 6
  • 28