How to get total count of Items in DropDownList Control in ASP.Net

Here, we will learn how to get total number of count of Items in DropDownList control in ASP.Net C#.

We will learn with an Example of asp.net C#.

First Design the asp.net web form:

 <table>
<tr>
<td style=”width: 100px; text-align: right”>
Select Value :</td>
<td style=”width: 100px; text-align: left”>
<asp:DropDownList ID=”Drpvalue” runat=”server” Width=”128px”>
<asp:ListItem Value=”0″>SELECT</asp:ListItem>
<asp:ListItem Value=”Meera”>Meera</asp:ListItem>
<asp:ListItem Value=”Academy”>Academy</asp:ListItem>
<asp:ListItem Value=”ASP”>ASP</asp:ListItem>
<asp:ListItem Value=”PHP”>PHP</asp:ListItem>
<asp:ListItem Value=”SQL”>SQL</asp:ListItem>
</asp:DropDownList></td>
<td style=”width: 100px; text-align: left”>
</td>
</tr>
<tr>
<td style=”width: 100px; text-align: right”>
&nbsp;</td>
<td style=”width: 100px; text-align: left”>
<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”COUNT” /></td>
<td style=”width: 100px; text-align: left”>
</td>
</tr>
<tr>
<td colspan=”3″ style=”text-align: center”>
<asp:Label ID=”Label1″ runat=”server” Font-Bold=”True” ForeColor=”Purple”></asp:Label></td>
</tr>
</table>

The ASP.Net example of DropDownList control output is:

Get Count of DropDownList Items in ASP.Net C#
Get Count of DropDownList Items in ASP.Net C#

Now, write the below code on Button Click events :

    protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = “Total Record = “+ Drpvalue.Items.Count.ToString();
}

I hope this asp.net tutorials will help you..

Leave a Reply

Your email address will not be published. Required fields are marked *