How to Count Total Items in DropDownList using JQuery


If you are using ASP.NET 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;

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments 1

user
Abhishek Reddy
  • 23 June 2012

This Tutorial super.

Add Comment