ListItemCollection.Remove Method (String)
.NET Framework 2.0
Removes a ListItem from the collection that represents the specified string.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
The following code example demonstrates the Remove method the ListItemCollection class. It creates a ListBox control with some list items in it. The user enters the text of the item to delete in a TextBox control named Delete. The Click event handler of the Button1 control deletes the selected item from the ListBox control.
ListItem myListItem = new ListItem(Delete.get_Text().ToLower(),
Delete.get_Text().ToLower());
// Check whether the 'ListItem' is present in the 'ListBox' or not.
if(itemCollection.Contains(myListItem)) {
String deleteString=Delete.get_Text();
// Delete the listitem entered by the user in textfield.
itemCollection.Remove(deleteString.ToLower());
Message.set_Text("<font color='green'><b>Deleted "
+ "Successfully</b></font>");
}
else {
Message.set_Text("<font color='red'><b>No ListItem with the "
+ "given name is present in the ListBox for "
+ "deletion.</b></font>");
}
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Community Additions
ADD
Show: