get the selected items in checkboxlist


There are many ways to get items from CheckBoxList. Bellow some codes are presented.
On aspx page,
<asp:CheckBoxList ID="chkbokxlist" runat="server"></asp:CheckBoxList> 
1- Code behind 
       foreach (ListItem i in chkbokxlist.Items)
        {
            if (i.Selected)
            {
            //your code here
            }
        }
2- Code behind
        var itm = chkbokxlist.Items.Cast<ListItem>().Where(x => x.Selected);
        foreach (ListItem i in itm)
        {
            if (i.Selected)
            {
            // your code
            }       
        }


Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...