ListItemCollection.Remove Metoda

Definicja

Usuwa obiekt ListItem z kolekcji.

Przeciążenia

Remove(String)

Usuwa element reprezentowany ListItem przez określony ciąg z kolekcji.

Remove(ListItem)

Usuwa określony ListItem element z kolekcji.

Remove(String)

Usuwa element reprezentowany ListItem przez określony ciąg z kolekcji.

public:
 void Remove(System::String ^ item);
public void Remove (string item);
member this.Remove : string -> unit
Public Sub Remove (item As String)

Parametry

item
String

Element String reprezentujący element do usunięcia z kolekcji.

Przykłady

W poniższym przykładzie pokazano metodę RemoveListItemCollection klasy . Strona sieci Web zawiera kontrolkę ListBox zawierającą niektóre elementy listy i kontrolkę TextBox o nazwie Delete. Użytkownik wprowadza tekst elementu do usunięcia w kontrolce TextBox . Procedura Click obsługi zdarzeń kontrolki Button1 usuwa wybrany element z ListItemCollection obiektu, a w związku z tym z kontrolki ListBox .

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>";
}               

     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

Uwagi

Remove Użyj metody , aby usunąć ListItem obiekt z kolekcji. Ta metoda tworzy ListItem obiekt przy użyciu tekstu parametru item , a następnie usuwa go ListItem z kolekcji. Określony item tekst musi być zgodny z właściwością Value i tekstem istniejącego ListItem obiektu dokładnie; w przeciwnym razie żaden element nie zostanie usunięty.

Zobacz też

Dotyczy

Remove(ListItem)

Usuwa określony ListItem element z kolekcji.

public:
 void Remove(System::Web::UI::WebControls::ListItem ^ item);
public void Remove (System.Web.UI.WebControls.ListItem item);
member this.Remove : System.Web.UI.WebControls.ListItem -> unit
Public Sub Remove (item As ListItem)

Parametry

item
ListItem

Element ListItem do usunięcia z kolekcji.

Przykłady

Poniższy przykład kodu przedstawia tworzenie ListItemCollection obiektów, dodawanie elementów do kolekcji i usuwanie elementów z kolekcji. W przykładzie nazwana listBoxData jest używana jako źródło danych dla ListBox kontrolki o nazwie ListBox1, a wywołanie ListItemCollectionddBoxData jest używane jako źródło danych dla DropDownList kontrolki o nazwie DropDownList1.ListItemCollection Aby wyświetlić ten kod w w pełni działającym przykładzie WebControl , zobacz temat klasy.

//Set the SelectedIndex to -1 so no items are selected.
// The new item will be set as the selected item when it is added.
DropDownList1.SelectedIndex = -1;
// Add the selected item to DropDownList1.
DropDownList1.Items.Add(ListBox1.SelectedItem);
// Delete the selected item from ListBox1.
ListBox1.Items.Remove(ListBox1.SelectedItem);
' Add the selected item to DropDownList1.
DropDownList1.Items.Add(ListBox1.SelectedItem)
' Delete the selected item from ListBox1.
ListBox1.Items.Remove(ListBox1.SelectedItem)

Uwagi

Remove Użyj metody , aby usunąć element ListItem z kolekcji. Ta implementacja metody przyjmuje ListItem określony przez item parametr i usuwa ją z kolekcji.

Zobacz też

Dotyczy