ListBox remove all items
listbox is an asp.net list web server control. listbox allow users to select multiple items if SelectionMode
property value set to Multiple. listbox can contain a collection of ListItem objects.
listbox Items property gets the collection of items in listbox control. asp.net developers can add or remove items from listbox by adding or removing items from this items collection object.
developers can clear (remove all) items from listbox by calling its Items.Clear() method. the following c# example demonstrate us how can we delete all items from listbox control programmatically at run time in asp.net.
listbox Items property gets the collection of items in listbox control. asp.net developers can add or remove items from listbox by adding or removing items from this items collection object.
developers can clear (remove all) items from listbox by calling its Items.Clear() method. the following c# example demonstrate us how can we delete all items from listbox control programmatically at run time in asp.net.
ListBoxItemsClear.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
ListBox1.Items.Clear();
Label1.Text = "ListBox Items Clear successfully!";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to clear list items in ListBox (remove all items)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Red">asp.net ListBox Example: Items Clear</h2>
<asp:Label
ID="Label1"
runat="server"
ForeColor="SandyBrown"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Label
ID="Label2"
runat="server"
Text="asp.net Controls"
Font-Bold="true"
ForeColor="SeaGreen"
>
</asp:Label>
<br />
<asp:ListBox
ID="ListBox1"
runat="server"
AutoPostBack="false"
>
<asp:ListItem>XML</asp:ListItem>
<asp:ListItem>ListBox</asp:ListItem>
<asp:ListItem>ImageMap</asp:ListItem>
<asp:ListItem>ListView</asp:ListItem>
<asp:ListItem>RequiredFieldValidator</asp:ListItem>
</asp:ListBox>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="Clear List Items"
Font-Bold="true"
ForeColor="Navy"
OnClick="Button1_Click"
/>
</div>
</form>
</body>
</html>

