How to findout the length of CheckBoxlist on serverside?
I have a checkboxlist in a div which shows name gettin data from db. I have to findout the lenght of this checkboxlist on OnSelectedIndexChanged to make some db action on selected item/value. S开发者_开发知识库omeone help me out!!!!!
Presuming your CheckBoxList
variable is called checkboxlist
use the following to determine the amount of items:
int numberOfItems = checkboxlist.Items.Count
The CheckBoxList.Items
property returns a ListItemCollection
containing your controls, from here you can use the count property to determine the length of the list or the number of items it contains.
<asp:CheckBoxList id="Check1" RepeatLayout="flow" runat="server" AutoPostBack="true" >
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:CheckBoxList>
Protected Sub Check1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Check1.SelectedIndexChanged
Dim items As String = Check1.Items.Count
End Sub
精彩评论