May 10, 2012

How to Count Total Items in DropDownList using JQuery


You have a DropDownList control and you want to count the total number of items in the
DropDownList using JQuery. You can using following JQuery code snippet.
Here is the code for DropDownList control.
<asp:DropDownList ID="DropDownList1" runat="server" >
   <asp:ListItem Value="1">Germany</asp:ListItem>
   <asp:ListItem Value="2">France</asp:ListItem>
   <asp:ListItem Value="3">Brazil</asp:ListItem>
</asp:DropDownList>

Following JQuery code snippet will give you total number of items in the above DropDownList control.
var items = $("#DropDownList1 option").length;

0 comments:

Post a Comment

Your comments:

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More