ListItemCollection.Remove Method (String)

Removes a ListItem from the collection that represents the specified string.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public:
void Remove (
	String^ item
)
public void Remove (
	String item
)
public function Remove (
	item : String
)
Not applicable.

Parameters

item

A System.String that represents the item to remove from the collection.

Use the Remove method to remove a ListItem object from the collection. This implementation of the method creates a ListItem object using the text in the item parameter and then removes this ListItem from the collection. The specified item parameter must match the Value property of an existing ListItem object, or no item is removed from the collection.

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.

No code example is currently available or this language may not be supported.
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 Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: