Condividi tramite


TreeNodeBinding.Depth Proprietà

Definizione

Ottiene o imposta la profondità del nodo in corrispondenza della quale viene applicato l'oggetto 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

Valore della proprietà

Profondità del nodo in corrispondenza della quale viene applicato l'oggetto TreeNodeBinding . Il valore predefinito è -1, a indicare che la Depth proprietà non è impostata.

Attributi

Esempio

Questa sezione contiene due esempi di codice. Il primo esempio di codice illustra come usare la Depth proprietà per applicare un TreeNodeBinding oggetto a una profondità del nodo specifica. Il secondo esempio di codice fornisce dati XML di esempio per il primo esempio di codice.

Nell'esempio di codice seguente viene illustrato come utilizzare la Depth proprietà per applicare un TreeNodeBinding oggetto a una profondità del nodo specifica. Affinché questo esempio funzioni correttamente, è necessario copiare i dati XML di esempio, forniti dopo questo esempio di codice, in un file denominato 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>

Nell'esempio di codice seguente vengono forniti dati XML di esempio per l'esempio di codice precedente.

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

Commenti

Una profondità del nodo specifica il livello del nodo associato. Ad esempio, la dichiarazione seguente TreeNodeBinding associa Name i campi e ID dell'origine dati alle proprietà eValue, rispettivamente, di tutti i nodi con una profondità pari a Text 0:

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

Quando si crea un TreeNodeBinding oggetto, è necessario specificare i criteri per l'associazione. I criteri indicano quando un elemento di dati deve essere associato a un nodo. È possibile specificare la Depth proprietà o DataMember o entrambe le proprietà. Esiste un lieve miglioramento delle prestazioni specificando entrambi.

Dopo aver stabilito i criteri di associazione, è possibile associare una proprietà di un TreeNode oggetto che può essere associato a un valore. È possibile eseguire il binding a un campo di un elemento di dati o a un valore statico. Se associato a un valore statico, tutti gli TreeNode oggetti a cui viene applicato l'oggetto TreeNodeBinding condividono lo stesso valore.

Il valore di questa proprietà viene archiviato nello stato di visualizzazione.

Si applica a

Vedi anche