Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get selected items count in asp:checkboxlist

i have a checkboxlist control

<asp:CheckBoxList ID="chkselectedItems" Font-Size="12px" runat="server"> 
 </asp:CheckBoxList>

and i created listitems on it dynamically.If i checked more than one item from the checkbox list, How i get the selected item count using asp.net

thanks

like image 697
ranjenanil Avatar asked May 05 '12 09:05

ranjenanil


People also ask

What is CheckBox list in asp net?

ASP.NET CheckBoxList is a web control that can be used to collate the items that can be checked, thus giving the user the ability to select multiple items simultaneously. This list of items in the CheckBoxList can be dynamically generated using the Data Binding functions.


1 Answers

Use this single line of code:

int selectedCount = chkselectedItems.Items.Cast<ListItem>().Count(li => li.Selected);
like image 98
Maciej Avatar answered Oct 06 '22 00:10

Maciej