Here in this ASP.NET Example of DropDownList Control we will learn to use Clear(), Remove() and RemoveAt() method in ASP.Net with C# Programmatically.
First we design the ASP.Net web page with One DropDownList Control and Three Button Control.
The HTML Code for asp.net web page is:
<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”>
<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”CLEAR” /></td>
<td style=”width: 100px”>
<asp:Button ID=”Button2″ runat=”server” OnClick=”Button2_Click” Text=”REMOVE” /></td>
<td style=”width: 100px; text-align: left”>
<asp:Button ID=”Button3″ runat=”server” OnClick=”Button3_Click” Text=”REMOVE AT” /></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 Design output of SAP.Net Example is:
Use Clear() in DropdownList control in ASP.Net
write the below code on CLEAR Button for clear all the items from DropDownList.
protected void Button1_Click(object sender, EventArgs e)
{
Drpvalue.Items.Clear();
Label1.Text = “All Items Clear !”;
}
The ASP.NET DropDownList Control Clear() Method output is:
Now, For Remove a Item write below code on REMOVE Button Click Event:
protected void Button2_Click(object sender, EventArgs e)
{
Drpvalue.Items.Remove(“ASP”);
Label1.Text = “‘ASP’ Removed Successfully”;
}
The ASP.Net DropDownList Control Remove method output is:
Write Below code on ClearAt Button for Clear Item from particular Index in ASP.Net.
protected void Button3_Click(object sender, EventArgs e)
{
Drpvalue.Items.RemoveAt(2);
Label1.Text = “Item Removed from Position 2 !”;
}
The ASP.NET DropDownList control RemoveAt method output is:

I hope this asp.net CLear(), Remove() and RemoveAt() Method of DropDownList control will help you….