ListItemCollection.Remove 메서드

정의

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

오버로드

Name Description
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 컬렉션에서 제거할 항목을 나타내는 A입니다.

예제

다음 예제에서는 클래스의 Remove 메서드를 보여 줍니다 ListItemCollection . 웹 페이지에는 ListBox 일부 목록 항목이 포함된 컨트롤과 이름이 지정된 TextBox컨트롤이 Delete 포함되어 있습니다. 사용자가 컨트롤에 삭제할 항목의 텍스트를 입력합니다 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 텍스트는 기존 Value 개체의 속성 및 텍스트와 정확히 일치 ListItem 해야 합니다. 그렇지 않으면 항목이 제거되지 않습니다.

추가 정보

적용 대상

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 , 컬렉션에 항목을 추가하고, 컬렉션에서 항목을 제거하는 방법을 보여 줍니다. 이 예제에서 명명된 ListItemCollection 이름은 listBoxData 호출된 ListBox컨트롤의 ListBox1 데이터 원본으로 사용되며 ListItemCollection 호출 ddBoxData 은 호출DropDownList된 컨트롤의 DropDownList1 데이터 원본으로 사용됩니다. 완전히 작동하는 예제에서 이 코드를 보려면 클래스 항목을 참조 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 합니다. 이 메서드 구현은 매개 변수에 ListItem 지정된 값을 item 가져와 컬렉션에서 제거합니다.

추가 정보

적용 대상