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
)

Parameters

item

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

Use the Remove method to remove a ListItem from the collection. This implementation of the method creates a ListItem to represent the text specified by the item parameter. This ListItem is then 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 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.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: