This documentation is archived and is not being maintained.

ListItemCollection.Remove Method

Removes a ListItem from the collection.

Overload List

Removes the specified ListItem from the collection.

[Visual Basic] Overloads Public Sub Remove(ListItem)
[C#] public void Remove(ListItem);
[C++] public: void Remove(ListItem*);
[JScript] public function Remove(ListItem);

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

[Visual Basic] Overloads Public Sub Remove(String)
[C#] public void Remove(string);
[C++] public: void Remove(String*);
[JScript] public function Remove(String);

Example

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of Remove. For other examples that might be available, see the individual overload topics.
[Visual Basic] 

     Dim myListItem As ListItem = new ListItem(Delete.Text.ToLower(),Delete.Text.ToLower())
     ' Check whether the 'ListItem' is present in the 'ListBox' or not.
     If(ItemCollection.Contains(myListItem)) Then
     
        Dim deleteString As String =Delete.Text
        ' Delete the listitem entered by the user in textfield.
        ItemCollection.Remove(deleteString.ToLower())
        Message.Text="<font color='green'><b>Deleted Successfully</b></font>"
     Else
     
       Message.Text="<font color='red'><b>No ListItem with the given name is present in the ListBox for deletion.</b></font>"
     End If

[C#] 
ListItem myListItem = new ListItem(Delete.Text.ToLower(),Delete.Text.ToLower());
// Check whether the 'ListItem' is present in the 'ListBox' or not.
if(ItemCollection.Contains(myListItem))
{
   String deleteString=Delete.Text;
   // Delete the listitem entered by the user in textfield.
   ItemCollection.Remove(deleteString.ToLower());
   Message.Text="<font color='green'><b>Deleted Successfully</b></font>";
}
else
{
  Message.Text="<font color='red'><b>No ListItem with the given name is present in the ListBox for deletion.</b></font>";
}               

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

ListItemCollection Class | ListItemCollection Members | System.Web.UI.WebControls Namespace

Show: