To remove all the items, use the following:
foreach(ListItem item in ListBox1.Items)
{
ListBox1.Items.Remove(item);
}
If your just wanting to remove a single item you can use the following:
ListBox1.Items.RemoveAt(n); where n is the index of the item you want to
remove.
If you don't know the index of the item, then you can use:
ListItem item = ListBox1.Items.FindByValue(foo); where foo is a string
representing the value you're looking for.
ListBox1.Items.Remove(item);
or;
ListItem item = ListBox1.Items.FindByText(foo); where foo is a string
representing the text you're looking for.
ListBox1.Items.Remove(item);
Of course, replace "ListBox1" with the name of your ListBox control.
David Young
mg said:
How can I remove (using C#) the items previously added to a
System.Web.UI.WebControls.ListBox