Feb 3, 2015

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

            }

       

        }