TreeNodeBindingCollection.Remove(TreeNodeBinding) 메서드

정의

TreeNodeBinding 개체에서 지정한 TreeNodeBindingCollection 개체를 제거합니다.

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

매개 변수

binding
TreeNodeBinding

제거할 TreeNodeBinding입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 Remove 제거 하는 방법을 TreeNodeBinding 에서 프로그래밍 방식으로 개체를 TreeNodeBindingCollection 개체입니다. 이 예제가 제대로 작동 하려면에 대 한 Book.xml 라는 파일에이 섹션의 끝에 있는 XML 데이터를 복사 해야 합니다.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {

    // Use the Remove method to remove the TreeNodeBinding object
    // for the third-level nodes (index 2).
    TreeNodeBinding oldBinding = BookTreeView.DataBindings[2];
    BookTreeView.DataBindings.Remove(oldBinding);

    // Create a new TreeNodeBinding object and set its properties.
    TreeNodeBinding newBinding = new TreeNodeBinding();
    newBinding.DataMember = "Section";
    newBinding.TextField = "Subject";

    // Use the Add method to add the TreeNodeBinding object to the 
    // DataBindings collection.
    BookTreeView.DataBindings.Add(newBinding);

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBindingCollection Add and Remove Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBindingCollection Add and Remove Example</h3>
    
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' Use the Remove method to remove the TreeNodeBinding object
    ' for the third-level nodes (index 2).
    Dim oldBinding As TreeNodeBinding = BookTreeView.DataBindings(2)
    BookTreeView.DataBindings.Remove(oldBinding)

    ' Create a new TreeNodeBinding object and set its properties.
    Dim newBinding As TreeNodeBinding = New TreeNodeBinding
    newBinding.DataMember = "Section"
    newBinding.TextField = "Subject"

    ' Use the Add method to add the TreeNodeBinding object to the 
    ' DataBindings collection.
    BookTreeView.DataBindings.Add(newBinding)

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBindingCollection Add and Remove Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBindingCollection Add and Remove Example</h3>
    
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

다음은 앞의 코드 예제에 대 한 XML 데이터입니다.

<Book Title="Book Title">  
    <Chapter Heading="Chapter 1">  
        <Section Heading="Section 1"  
            Subject="Subject 1">  
        </Section>  
        <Section Heading="Section 2"  
            Subject="Subject 1">  
        </Section>  
    </Chapter>  
    <Chapter Heading="Chapter 2">  
        <Section Heading="Section 1"  
            Subject="Subject 1">  
        </Section>  
    </Chapter>  
</Book>  

설명

사용 하 여는 Remove 제거 된 방법 TreeNodeBinding 컬렉션의 개체입니다. 그런 다음 빈 위치에 맞게 해당 노드 아래에 있는 모든 항목 위로 이동 합니다. 이동된 된 항목의 인덱스도 업데이트 됩니다.

대신 사용 하 여 특정 인덱스에 있는 노드를 제거할 수 있습니다는 RemoveAt 메서드. 사용 하 여 컬렉션에서 모든 노드를 제거할 수도 있습니다는 Clear 메서드.

적용 대상

추가 정보