TreeNodeBinding.Depth プロパティ

定義

TreeNodeBinding オブジェクトが適用されるノードの深さを取得または設定します。

public:
 property int Depth { int get(); void set(int value); };
[System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public int Depth { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public int Depth { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Depth : int with get, set
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Depth : int with get, set
Public Property Depth As Integer

プロパティ値

TreeNodeBinding オブジェクトが適用されるノードの深さ。 既定値は -1 です。Depth プロパティが設定されていないことを示します。

属性

このセクションには、2 つのコード例が含まれています。 最初のコード例では、 プロパティを使用して、特定の Depth ノードの深さでオブジェクトを TreeNodeBinding 適用する方法を示します。 2 番目のコード例では、最初のコード例のサンプル XML データを提供します。

次のコード例では、 プロパティを使用して、特定の Depth ノードの深さでオブジェクトを TreeNodeBinding 適用する方法を示します。 この例を正しく機能させるには、このコード例の後に提供されるサンプル 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeViewBinding DataMember and Depth Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeViewBinding DataMember and Depth Example</h3>
    
      <!-- Set the DataMember and Depth properties of a -->
      <!-- TreeNodeBinding object declaratively. You  -->
      <!-- can render items at the same node level    -->
      <!-- by setting each item's Depth property to   -->
      <!-- the same value.                -->
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        runat="server">
          
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" Depth="0" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" Depth="1" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Appendix" Depth="1" 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeViewBinding DataMember and Depth Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeViewBinding DataMember and Depth Example</h3>
    
      <!-- Set the DataMember and Depth properties of a -->
      <!-- TreeNodeBinding object declaratively. You  -->
      <!-- can render items at the same node level    -->
      <!-- by setting each item's Depth property to   -->
      <!-- the same value.                -->
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        runat="server">
          
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" Depth="0" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" Depth="1" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Appendix" Depth="1" 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">  
        </Section>  
        <Section Heading="Section 2">  
        </Section>  
    </Chapter>  
    <Chapter Heading="Chapter 2">  
        <Section Heading="Section 1">  
        </Section>  
    </Chapter>  
    <Appendix Heading="Appendix A">  
    </Appendix>  
</Book>  

注釈

ノードの深さは、バインドされるノード レベルを指定します。 たとえば、次TreeNodeBindingの宣言では、データ ソースの フィールドと ID フィールドをそれぞれText、深さが 0 のすべてのノードの プロパティと Value プロパティにバインドNameします。

<asp:TreeNodeBinding Depth="0" TextField="Name" ValueField="ID">  

オブジェクトを作成するときは TreeNodeBinding 、バインドの条件を指定する必要があります。 条件は、データ項目をノードにバインドする必要があるタイミングを示します。 プロパティまたは DataMember プロパティ、または両方のDepthプロパティを指定できます。 両方を指定することで、パフォーマンスが若干向上します。

バインド条件が確立されたら、値にバインドできるオブジェクトの TreeNode プロパティをバインドできます。 データ項目のフィールドまたは静的な値にバインドできます。 静的な値にバインドすると、そのオブジェクトがTreeNodeBinding適用されるすべてのTreeNodeオブジェクトが同じ値を共有します。

このプロパティの値はビューステートに格納されます。

適用対象

こちらもご覧ください