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 방법을 보여 줍니다. 이 예제가 제대로 작동하려면 이 섹션의 끝에 있는 XML 데이터를 Book.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 컬렉션의 모든 노드를 제거할 수도 있습니다.

적용 대상

추가 정보