Remove all items from BulletedList
BulletedList is an asp.net list web server control that render a list of items in a
bulleted format in web browser. BulletedList Items property gets the collection of items in the BulletedList control.
A ListItem object represent an item in BulletedList server control. All ListItem objects contains in an items collection
of BulletedList control.
We can add or remove items from BulletedList by adding or removing items from its items collection. ListItemCollection.Clear method removes all ListItem objects from the collection. So if we want to delete (remove) all items from a BulletedList control, we can call the BulletedList Items.Clear() method.
The following c# example source code demonstrate us how can we remove all items from BulletedList programmatically at run time.
We can add or remove items from BulletedList by adding or removing items from its items collection. ListItemCollection.Clear method removes all ListItem objects from the collection. So if we want to delete (remove) all items from a BulletedList control, we can call the BulletedList Items.Clear() method.
The following c# example source code demonstrate us how can we remove all items from BulletedList programmatically at run time.
BulletedListItemsClear.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
BulletedList1.Items.Clear();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to remove (clear) all items from BulletedList</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">BulletedList: Items.Clear()</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
ForeColor="Crimson"
Text="asp.net controls"
>
</asp:Label>
<asp:BulletedList
ID="BulletedList1"
runat="server"
Width="275"
BorderColor="Crimson"
BackColor="DarkOrange"
BorderWidth="3"
ForeColor="Snow"
>
<asp:ListItem>Wizard</asp:ListItem>
<asp:ListItem>DetailsView</asp:ListItem>
<asp:ListItem>EntityDataSource</asp:ListItem>
<asp:ListItem>SiteMapPath</asp:ListItem>
<asp:ListItem>Login</asp:ListItem>
</asp:BulletedList>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Font-Bold="true"
ForeColor="Crimson"
Text="Clear BulletedList Items"
OnClick="Button1_Click"
/>
</div>
</form>
</body>
</html>

