Share via


ListItemCollection.Remove 메서드

정의

컬렉션에서 ListItem를 제거합니다.

오버로드

Remove(String)

컬렉션에서 지정된 문자열로 나타내는 ListItem을 제거합니다.

Remove(ListItem)

지정된 ListItem를 컬렉션에서 제거합니다.

Remove(String)

컬렉션에서 지정된 문자열로 나타내는 ListItem을 제거합니다.

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

매개 변수

item
String

컬렉션에서 제거할 항목을 나타내는 String입니다.

예제

다음 예제에서는 클래스의 Remove 메서드를 보여 줍니다 ListItemCollection . 웹 페이지에는 일부 목록 항목이 있는 컨트롤과 라는 Delete컨트롤이 TextBox 포함되어 ListBox 있습니다. 사용자가 삭제할 항목의 텍스트를 컨트롤에 TextBox 입력합니다. Click 컨트롤의 Button1 이벤트 처리기는 개체에서 ListItemCollection 선택한 항목을 삭제하므로 컨트롤에서 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

설명

메서드를 Remove 사용하여 컬렉션에서 개체를 ListItem 제거합니다. 이 메서드는 ListItem 매개 변수 텍스트를 사용하여 개체를 item 만든 다음 컬렉션에서 제거 ListItem 합니다. 지정한 item 텍스트는 속성과 기존 ListItem 개체의 텍스트와 정확히 일치 Value 해야 합니다. 그렇지 않으면 항목이 제거되지 않습니다.

추가 정보

적용 대상

Remove(ListItem)

지정된 ListItem를 컬렉션에서 제거합니다.

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)

매개 변수

item
ListItem

컬렉션에서 제거할 ListItem입니다.

예제

다음 코드 예제에서는 개체를 만들고 ListItemCollection , 컬렉션에 항목을 추가하고, 컬렉션에서 항목을 제거하는 방법을 보여 줍니다. 이 예제에서 명명 listBoxDataListItemCollection 는 라는 ListBox1컨트롤의 ListBox 데이터 원본으로 사용되며 ListItemCollection 호출 ddBoxData 된 는 라는 DropDownList1컨트롤의 DropDownList 데이터 원본으로 사용됩니다. 완전히 작동하는 예제에서 이 코드를 보려면 클래스 항목을 참조 WebControl 하세요.

//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)

설명

메서드를 Remove 사용하여 컬렉션에서 을 ListItem 제거합니다. 메서드의 이 구현은 매개 변수로 지정된 을 item 가져와 ListItem 컬렉션에서 제거합니다.

추가 정보

적용 대상