TreeView 類別

定義

在樹狀中顯示階層式資料,例如目錄。

public ref class TreeView : System::Web::UI::WebControls::HierarchicalDataBoundControl, System::Web::UI::ICallbackEventHandler, System::Web::UI::IPostBackDataHandler, System::Web::UI::IPostBackEventHandler
[System.Web.UI.ControlValueProperty("SelectedValue")]
public class TreeView : System.Web.UI.WebControls.HierarchicalDataBoundControl, System.Web.UI.ICallbackEventHandler, System.Web.UI.IPostBackDataHandler, System.Web.UI.IPostBackEventHandler
[<System.Web.UI.ControlValueProperty("SelectedValue")>]
type TreeView = class
    inherit HierarchicalDataBoundControl
    interface IPostBackEventHandler
    interface IPostBackDataHandler
    interface ICallbackEventHandler
Public Class TreeView
Inherits HierarchicalDataBoundControl
Implements ICallbackEventHandler, IPostBackDataHandler, IPostBackEventHandler
繼承
屬性
實作

範例

本節包含七個程式碼範例:

  • 第一個程式碼範例示範如何設定第二個程式碼範例的框架。

  • 第二個程式碼範例示範如何使用宣告式語法在 控制項中 TreeView 顯示靜態資料。

  • 第三個程式碼範例示範如何將控制項系結 TreeView 至 XML 資料來源。

  • 第四個程式碼範例提供第三個程式碼範例的範例 XML 資料。

  • 第五個程式碼範例示範如何將控制項系結至 SiteMapDataSource 控制項,以使用 TreeView 控制項進行網站導覽。

  • 第六個程式碼範例提供第五個程式碼範例的範例網站地圖資料。

  • 第七個程式碼範例示範如何從用戶端填入 控制項中的 TreeView 節點。

下列程式碼範例示範如何設定下列程式碼範例的框架。


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>TreeView Frameset Example</title>
</head>
         
    <frameset cols="30%, 75%">
   
        <frame title="MenuFrame" name="Menu" src="TreeViewFramecs.aspx"/>
        <frame title="ContentFrame" name="Content" src="Home.aspx"/> 
           
    </frameset>      
   
</html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>TreeView Frameset Example</title>
</head>
         
    <frameset cols="30%, 75%">
   
        <frame title="MenuFrame" name="Menu" src="TreeViewFramevb.aspx"/>
        <frame title="ContentFrame" name="Content" src="Home.aspx"/> 
           
    </frameset>      
   
</html>

下列程式碼範例示範如何使用宣告式語法在 控制項中 TreeView 顯示靜態資料。 在上述範例的框架組中,會使用此範例來顯示目錄。


<%@ 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>TreeView Declarative Syntax Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView Declarative Syntax Example</h3>
      
      <asp:TreeView id="SampleTreeView" 
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">
             
            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">
               
              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>
                 
            </asp:TreeNode>              
            
            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">
               
            </asp:TreeNode> 
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>

    </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>TreeView Declarative Syntax Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView Declarative Syntax Example</h3>
      
      <asp:TreeView id="SampleTreeView" 
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">
             
            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">
               
              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>
                 
            </asp:TreeNode>              
            
            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">
               
            </asp:TreeNode> 
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>

    </form>
  </body>
</html>

下列程式碼範例示範如何將 控制項系結 TreeView 至 XML 資料來源。 若要讓此範例正常運作,您必須將此程式碼範例之後提供的範例 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>TreeView XML Data Binding Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView XML Data Binding 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView XML Data Binding Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView XML Data Binding 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">
        </Section>
        <Section Heading="Section 2">
        </Section>
    </Chapter>
    <Chapter Heading="Chapter 2">
        <Section Heading="Section 1">
        </Section>
    </Chapter>
</Book>

下列程式碼範例示範如何藉由將控制項系結至 SiteMapDataSource 控制項,將 TreeView 控制項用於網站導覽。 若要讓此範例正常運作,您必須將此程式碼範例之後提供的範例網站地圖資料複製到名為 Web.sitemap 的檔案。


<%@ 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>TreeView AutoGenerateBindings Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView AutoGenerateBindings Example</h3>
    
      <!-- Set the AutoGenerateBindings property -->
      <!-- to false declaratively to allow for   -->
      <!-- the user-defined Bindings collection. -->
      <asp:TreeView id="SiteTreeView" 
        DataSourceID="SiteMapSource"
        AutoGenerateDataBindings="False"
        runat="server">
        
        <DataBindings>
        
          <asp:TreeNodeBinding TextField="title" NavigateUrlField="url"/>
        
        </DataBindings>
            
      </asp:TreeView>
      
      <asp:SiteMapDataSource ID="SiteMapSource" runat="server"/>
         
    </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>TreeView AutoGenerateBindings Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView AutoGenerateBindings Example</h3>
    
      <!-- Set the AutoGenerateBindings property -->
      <!-- to false declaratively to allow for   -->
      <!-- the user-defined Bindings collection. -->
      <asp:TreeView id="SiteTreeView" 
        DataSourceID="SiteMapSource"
        AutoGenerateDataBindings="False"
        runat="server">
        
        <DataBindings>
        
          <asp:TreeNodeBinding TextField="title" NavigateUrlField="url"/>
        
        </DataBindings>
            
      </asp:TreeView>
      
      <asp:SiteMapDataSource ID="SiteMapSource" runat="server"/>
         
    </form>
  </body>
</html>

下列程式碼範例提供上述程式碼範例的範例網站地圖資料。

<siteMap>
    <siteMapNode title="Home" description="Home" url="default.aspx">
        <siteMapNode title="Products" description="Products" url="Products.aspx">
            <siteMapNode title="Computers" url="Computers.aspx"/>
            <siteMapNode title="Accessories" url="Accessories.aspx"/>
        </siteMapNode>
    </siteMapNode>
</siteMap>

下列程式碼範例示範如何從用戶端填入 控制項中的 TreeView 節點。 啟用用戶端節點擴展時,會在用戶端動態填入節點,而不需要回傳至伺服器。


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

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

  void PopulateNode(Object sender, TreeNodeEventArgs e)
  {

    // Call the appropriate method to populate a node at a particular level.
    switch(e.Node.Depth)
    {
      case 0:
        // Populate the first-level nodes.
        PopulateCategories(e.Node);
        break;
      case 1:
        // Populate the second-level nodes.
        PopulateProducts(e.Node);
        break;
      default:
        // Do nothing.
        break;
    }
    
  }

  void PopulateCategories(TreeNode node)
  {
    
    // Query for the product categories. These are the values
    // for the second-level nodes.
    DataSet ResultSet = RunQuery("Select CategoryID, CategoryName From Categories");

    // Create the second-level nodes.
    if(ResultSet.Tables.Count > 0)
    {
    
      // Iterate through and create a new node for each row in the query results.
      // Notice that the query results are stored in the table of the DataSet.
      foreach (DataRow row in ResultSet.Tables[0].Rows)
      {
        
        // Create the new node. Notice that the CategoryId is stored in the Value property 
        // of the node. This will make querying for items in a specific category easier when
        // the third-level nodes are created. 
        TreeNode newNode = new TreeNode();
        newNode.Text = row["CategoryName"].ToString(); 
        newNode.Value = row["CategoryID"].ToString();        

        // Set the PopulateOnDemand property to true so that the child nodes can be 
        // dynamically populated.
        newNode.PopulateOnDemand = true;
        
        // Set additional properties for the node.
        newNode.SelectAction = TreeNodeSelectAction.Expand;
        
        // Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(newNode);
        
      }
      
    }
    
  }

  void PopulateProducts(TreeNode node)
  {

    // Query for the products of the current category. These are the values
    // for the third-level nodes.
    DataSet ResultSet = RunQuery("Select ProductName From Products Where CategoryID=" + node.Value);

    // Create the third-level nodes.
    if(ResultSet.Tables.Count > 0)
    {
    
      // Iterate through and create a new node for each row in the query results.
      // Notice that the query results are stored in the table of the DataSet.
      foreach (DataRow row in ResultSet.Tables[0].Rows)
      {
      
        // Create the new node.
        TreeNode NewNode = new TreeNode(row["ProductName"].ToString());
        
        // Set the PopulateOnDemand property to false, because these are leaf nodes and
        // do not need to be populated.
        NewNode.PopulateOnDemand = false;
        
        // Set additional properties for the node.
        NewNode.SelectAction = TreeNodeSelectAction.None;
        
        // Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(NewNode);
        
      }
      
    }

  }

  DataSet RunQuery(String QueryString)
  {

    // Declare the connection string. This example uses Microsoft SQL Server 
    // and connects to the Northwind sample database.
    String ConnectionString = "server=localhost;database=NorthWind;Integrated Security=SSPI"; 

    SqlConnection DBConnection = new SqlConnection(ConnectionString);
    SqlDataAdapter DBAdapter;
    DataSet ResultsDataSet = new DataSet();

    try
    {

      // Run the query and create a DataSet.
      DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
      DBAdapter.Fill(ResultsDataSet);

      // Close the database connection.
      DBConnection.Close();

    }
    catch(Exception ex)
    {

      // Close the database connection if it is still open.
      if(DBConnection.State == ConnectionState.Open)
      {
        DBConnection.Close();
      }
      
      Message.Text = "Unable to connect to the database.";

    }

    return ResultsDataSet;

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView PopulateNodesFromClient Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView PopulateNodesFromClient Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        EnableClientScript="true"
        PopulateNodesFromClient="true"  
        OnTreeNodePopulate="PopulateNode"
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Text="Inventory" 
            SelectAction="Expand"  
            PopulateOnDemand="true"/>
        
        </Nodes>
        
      </asp:TreeView>
      
      <br /><br />
      
      <asp:Label id="Message" runat="server"/>

    </form>
  </body>
</html>

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

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

  Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs)

    ' Call the appropriate method to populate a node at a particular level.
    Select Case e.Node.Depth

      Case 0
        ' Populate the first-level nodes.
        PopulateCategories(e.Node)

      Case 1
        ' Populate the second-level nodes.
        PopulateProducts(e.Node)

      Case Else
        ' Do nothing.

    End Select

  End Sub

  Sub PopulateCategories(ByVal node As TreeNode)

    ' Query for the product categories. These are the values
    ' for the second-level nodes.
    Dim ResultSet As DataSet = RunQuery("Select CategoryID, CategoryName From Categories")

    ' Create the second-level nodes.
    If ResultSet.Tables.Count > 0 Then

      ' Iterate through and create a new node for each row in the query results.
      ' Notice that the query results are stored in the table of the DataSet.
      Dim row As DataRow

      For Each row In ResultSet.Tables(0).Rows

        ' Create the new node. Notice that the CategoryId is stored in the Value property 
        ' of the node. This will make querying for items in a specific category easier when
        ' the third-level nodes are created. 
        Dim newNode As TreeNode = New TreeNode()
        Newnode.Text = row("CategoryName").ToString() 
        Newnode.Value = row("CategoryID").ToString()

        ' Set the PopulateOnDemand property to true so that the child nodes can be 
        ' dynamically populated.
        newNode.PopulateOnDemand = True

        ' Set additional properties for the node.
        newNode.SelectAction = TreeNodeSelectAction.Expand

        ' Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(newNode)

      Next

    End If

  End Sub

  Sub PopulateProducts(ByVal node As TreeNode)

    ' Query for the products of the current category. These are the values
    ' for the third-level nodes.
    Dim ResultSet As DataSet = RunQuery("Select ProductName From Products Where CategoryID=" & node.Value)

    ' Create the third-level nodes.
    If ResultSet.Tables.Count > 0 Then

      ' Iterate through and create a new node for each row in the query results.
      ' Notice that the query results are stored in the table of the DataSet.
      Dim row As DataRow

      For Each row In ResultSet.Tables(0).Rows

        ' Create the new node.
        Dim NewNode As TreeNode = New TreeNode(row("ProductName").ToString())

        ' Set the PopulateOnDemand property to false, because these are leaf nodes and
        ' do not need to be populated.
        NewNode.PopulateOnDemand = False

        ' Set additional properties for the node.
        NewNode.SelectAction = TreeNodeSelectAction.None

        ' Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(NewNode)

      Next

    End If

  End Sub

  Function RunQuery(ByVal QueryString As String) As DataSet

    ' Declare the connection string. This example uses Microsoft SQL Server 
    ' and connects to the Northwind sample database.
    Dim ConnectionString As String = "server=localhost;database=NorthWind;Integrated Security=SSPI"

    Dim DBConnection As SqlConnection = New SqlConnection(ConnectionString)
    Dim DBAdapter As SqlDataAdapter
    Dim ResultsDataSet As DataSet = New DataSet

    Try

      ' Run the query and create a DataSet.
      DBAdapter = New SqlDataAdapter(QueryString, DBConnection)
      DBAdapter.Fill(ResultsDataSet)

      ' Close the database connection.
      DBConnection.Close()

    Catch ex As Exception

      ' Close the database connection if it is still open.
      If DBConnection.State = ConnectionState.Open Then

        DBConnection.Close()

      End If

      Message.Text = "Unable to connect to the database."

    End Try

    Return ResultsDataSet

  End Function

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView PopulateNodesFromClient Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView PopulateNodesFromClient Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        EnableClientScript="true"
        PopulateNodesFromClient="true"  
        OnTreeNodePopulate="PopulateNode"
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Text="Inventory" 
            SelectAction="Expand"  
            PopulateOnDemand="true"/>
        
        </Nodes>
        
      </asp:TreeView>
      
      <br /><br />
      
      <asp:Label id="Message" runat="server"/>

    </form>
  </body>
</html>

備註

本主題內容:

簡介

控制項 TreeView 可用來在樹狀結構中顯示階層式資料,例如目錄或檔案目錄,並支援下列功能:

  • 資料系結,可讓控制項的節點系結至 XML、表格式或關聯式資料。

  • 與 控制項整合 SiteMapDataSource 的網站導覽。

  • 可顯示為純文字或超連結的節點文字。

  • 以程式設計方式存取 TreeView 物件模型,以動態方式建立樹狀結構、填入節點、設定屬性等等。

  • 支援的瀏覽器) 上的用戶端節點擴展 (。

  • 顯示每個節點旁核取方塊的能力。

  • 可透過主題、使用者定義影像和樣式來自訂外觀。

    注意

    只有在 TreeView 設定 true 為 時 EnableClientScript ,控制項才設計成在 控制項內 UpdatePanel 使用。 UpdatePanel 控制項可用來更新頁面的選取區域,而不是使用回傳更新整個頁面。 如需詳細資訊,請參閱 UpdatePanel 控制項概觀部分頁面轉譯概觀

節點

控制項 TreeView 是由節點所組成。 樹狀結構中的每個專案都會稱為節點,並以 物件表示 TreeNode 。 節點類型的定義如下:

  • 包含其他節點的節點稱為 父節點

  • 另一個節點所包含的節點稱為 子節點

  • 沒有子系的節點稱為 分葉節點

  • 不是任何其他節點所包含的節點,而是所有其他節點的上階節點是 根節點

節點可以是父節點和子節點,但根節點、父節點和分葉節點互斥。 節點的數個視覺和行為屬性取決於節點是否為根節點、子節點或分葉節點。

雖然典型的樹狀結構只有一個根節點,但 TreeView 控制項可讓您將多個根節點新增至樹狀結構。 當您想要顯示專案清單而不顯示單一根節點時,如同產品類別清單一樣,這會很有用。

每個節點都有 Text 屬性和 Value 屬性。 屬性的值 Text 會顯示在 中 TreeView ,而 Value 屬性是用來儲存節點的任何其他資料,例如傳遞至與節點相關聯之回傳事件的資料。

節點可以有兩種模式之一:選取模式和瀏覽模式。 根據預設,節點處於選取模式。 若要將節點放入瀏覽模式,請將 NavigateUrl 節點的 屬性設定為空字串以外的值, (「」) 。 若要將節點放入選取模式,請將 NavigateUrl 節點的 屬性設定為空字串 (「」) 。

注意

某些網際網路瀏覽器有可能會影響控制項效能 TreeView 的限制。 例如,Microsoft Internet Explorer 6.0 的 URL 字元限制為 2067 個字元。。 如果節點 URL 中的字元數目大於該數位,則展開該節點將會失敗,而且不會擲回例外狀況。

靜態資料

控制項最簡單的資料模型 TreeView 是靜態資料。 若要使用宣告式語法顯示靜態資料,請先在控制項的 TreeView 開頭和結束記號之間巢狀開啟和結尾 <Nodes> 標記。 接下來,藉由在開頭和結尾 <Nodes> 標記之間巢狀 <asp:TreeNode> 專案來建立樹狀結構。 每個 <asp:TreeNode> 元素都代表樹狀結構中的節點,並對應至 TreeNode 物件。 您可以藉由設定其 <asp:TreeNode> 元素的屬性來設定每個節點的屬性。 若要建立子節點,請在父節點的開頭和結尾 <asp:TreeNode> 標記之間巢狀其他 <asp:TreeNode> 元素。

系結至資料

控制項 TreeView 也可以系結至資料。 您可以使用兩種方法之一,將控制項系結 TreeView 至適當的資料來源類型:

系結至資料來源時,每個資料項目都包含多個屬性 (,例如具有數個屬性的 XML 元素) ,節點預設會顯示資料項目方法所 ToString 傳回的值。 在 XML 元素的情況下,節點會顯示專案名稱,其中顯示樹狀結構的基礎結構,但不是非常有用的。 您可以使用集合來指定樹狀節點 DataBindings 系結,將節點系結至特定資料項目屬性。 DataBindings集合包含 TreeNodeBinding 物件,定義資料項目與其系結之節點之間的關聯性。 您可以指定要在節點中顯示的系結準則和資料項目屬性。 如需樹狀節點系結的詳細資訊,請參閱 TreeNodeBinding

重要

惡意使用者可以建立回呼要求,並取得頁面開發人員未顯示之控制項節點 TreeView 的資料。 因此,資料來源必須實作資料的安全性。 請勿使用 MaxDataBindDepth 屬性來隱藏資料。

動態節點母體擴展

有時候,靜態定義樹狀結構並不實用,因為資料來源會傳回太多資料,或因為要顯示的資料取決於您在執行時間取得的資訊。 因此, TreeView 控制項支援動態節點母體擴展。 PopulateOnDemand當節點的 屬性設定 true 為 時,該節點會在展開節點時于執行時間填入。 若要動態填入節點,您必須定義包含邏輯的事件處理方法,以填入事件的節點 TreeNodePopulate

支援回呼腳本的瀏覽器也可以利用用戶端節點母體擴展。 (這包括 Internet Explorer 5.5 和更新版本,以及一些其他瀏覽器。) 用戶端節點擴展可讓 TreeView 控制項在使用者展開節點時使用用戶端腳本填入節點,而不需要往返伺服器。 如需用戶端節點母體擴展的詳細資訊,請參閱 PopulateNodesFromClient

自訂使用者介面

有許多方式可以自訂控制項的外觀 TreeView 。 首先,您可以為每個節點類型指定不同的樣式 (,例如字型大小和色彩) 。

如果您使用串聯樣式表單 (CSS) 自訂控制項的外觀,請使用內嵌樣式或個別的 CSS 檔案,但不能同時使用兩者。 同時使用內嵌樣式和個別的 CSS 檔案可能會導致非預期的結果。 如需搭配控制項使用樣式表單的詳細資訊,請參閱 Web 服務器控制項和 CSS 樣式

下表列出可用的節點樣式。

節點樣式屬性 描述
HoverNodeStyle 當滑鼠指標放在節點上方時,節點的樣式設定。
LeafNodeStyle 分葉節點的樣式設定。
NodeStyle 節點的預設樣式設定。
ParentNodeStyle 父節點的樣式設定。
RootNodeStyle 根節點的樣式設定。
SelectedNodeStyle 所選節點的樣式設定。

您也可以使用 LevelStyles 集合來控制樹狀結構內特定深度的節點樣式。 集合中的第一個樣式會對應至樹狀結構中第一層節點的樣式。 集合中的第二個樣式會對應至樹狀結構中第二層節點的樣式,依此類故。 這最常用來產生目錄樣式導覽功能表,其中特定深度的節點應該具有相同的外觀,不論節點是否具有子節點。

注意

如果使用集合針對特定深度層級 LevelStyles 定義樣式,該樣式會覆寫該深度節點的任何根、父系或分葉節點樣式設定。

改變控制面板的另一種方式是自訂控制項中顯示的 TreeView 影像。 您可以藉由設定下表所示的屬性,為控制項的不同部分指定自己的自訂映射集。

Image 屬性 描述
CollapseImageUrl 顯示可折迭節點指標之影像的 URL。 此映射通常是減號 () 。
ExpandImageUrl 顯示可展開節點指標之影像的 URL。 此影像通常是加號 (+) 。
LineImagesFolder 資料夾的 URL,其中包含用來將父節點連接到子節點的行影像。 屬性 ShowLines 也必須設定 true 為 ,這個屬性才能生效。
NoExpandImageUrl 針對不可展開的節點指標所顯示的影像 URL。

注意

您不需要自訂每個影像屬性。 如果未明確設定 image 屬性,則會使用內建的預設映射。

控制項 TreeView 也可讓您在節點旁邊顯示覆選框。 ShowCheckBoxes當 屬性設定為 以外的 TreeNodeTypes.None 值時,核取方塊會顯示在指定的節點類型旁邊。

注意

屬性 ShowCheckBoxes 可以設定為列舉成員值的位元組合 TreeNodeTypes

每次將頁面張貼到伺服器時, CheckedNodes 集合會自動填入選取的節點。 顯示覆選框時,每當貼文到伺服器之間的核取方塊狀態變更時,您可以使用 TreeNodeCheckChanged 事件來執行自訂常式。

事件

控制項 TreeView 提供數個您可以針對的事件進行程式設計。 這可讓您在事件發生時執行自訂常式。 下表列出 控制項所支援 TreeView 的事件。

事件 描述
TreeNodeCheckChanged 發生于控制項的 TreeView 核取方塊在貼文到伺服器之間變更狀態時。
SelectedNodeChanged 當在 TreeView 控制項中選取節點時就會發生。
TreeNodeExpanded 當在 TreeView 控制項中展開節點時就會發生。
TreeNodeCollapsed 當在 TreeView 控制項中摺疊節點時就會發生。
TreeNodePopulate 當在 PopulateOnDemand 控制項中展開 TreeView 屬性設為 true 的節點時發生。
TreeNodeDataBound 當資料項目繫結至 TreeView 控制項中的節點時就會發生。

捲動

控制項 TreeView 沒有內建捲動。 若要新增捲動,請將 TreeView 控制項放在 控制項中 Panel ,並將捲軸新增至 Panel 控制項。 如需詳細資訊,請參閱 Panel Web Server Control Overview

Accessibility

根據預設,此控制項所轉譯的標記可能不符合協助工具標準。 如需此控制項協助工具支援的詳細資訊,請參閱 ASP.NET 控制項和協助工具

宣告式語法

<asp:TreeView
    AccessKey="string"
    AutoGenerateDataBindings="True|False"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CollapseImageToolTip="string"
    CollapseImageUrl="uri"
    CssClass="string"
    DataSource="string"
    DataSourceID="string"
    EnableClientScript="True|False"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    ExpandDepth="string|FullyExpand|0|1|2|3|4|5|6|7|8|9|10|11|12|13|
        14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30"
    ExpandImageToolTip="string"
    ExpandImageUrl="uri"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
       Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    ID="string"
    ImageSet="Custom|XPFileExplorer|Msdn|WindowsHelp|Simple|Simple2|
        BulletedList|BulletedList2|BulletedList3|BulletedList4|
        Arrows|News|Contacts|Inbox|Events|Faq"
    LineImagesFolder="string"
    MaxDataBindDepth="integer"
    NodeIndent="integer"
    NodeWrap="True|False"
    NoExpandImageUrl="uri"
    OnDataBinding="DataBinding event handler"
    OnDataBound="DataBound event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnSelectedNodeChanged="SelectedNodeChanged event handler"
    OnTreeNodeCheckChanged="TreeNodeCheckChanged event handler"
    OnTreeNodeCollapsed="TreeNodeCollapsed event handler"
    OnTreeNodeDataBound="TreeNodeDataBound event handler"
    OnTreeNodeExpanded="TreeNodeExpanded event handler"
    OnTreeNodePopulate="TreeNodePopulate event handler"
    OnUnload="Unload event handler"
    PathSeparator="string"
    PopulateNodesFromClient="True|False"
    runat="server"
    ShowCheckBoxes="None|Root|Parent|Leaf|All"
    ShowExpandCollapse="True|False"
    ShowLines="True|False"
    SkinID="string"
    SkipLinkText="string"
    Style="string"
    TabIndex="integer"
    Target="string"
    ToolTip="string"
    Visible="True|False"
    Width="size"
>
        <DataBindings>
                <asp:TreeNodeBinding
                    DataMember="string"
                    Depth="integer"
                    FormatString="string"
                    ImageToolTip="string"
                    ImageToolTipField="string"
                    ImageUrl="uri"
                    ImageUrlField="string"
                    NavigateUrl="uri"
                    NavigateUrlField="string"
                    PopulateOnDemand="True|False"
                    SelectAction="Select|Expand|SelectExpand|None"
                    ShowCheckBox="string"
                    Target="string"
                    TargetField="string"
                    Text="string"
                    TextField="string"
                    ToolTip="string"
                    ToolTipField="string"
                    Value="string"
                    ValueField="string"
                />
        </DataBindings>
        <HoverNodeStyle />
        <LeafNodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
        <LevelStyles>
                <asp:TreeNodeStyle
                    BackColor="color name|#dddddd"
                    BorderColor="color name|#dddddd"
                    BorderStyle="NotSet|None|Dotted|Dashed|Solid|
                        Double|Groove|Ridge|Inset|Outset"
                    BorderWidth="size"
                    ChildNodesPadding="size"
                    CssClass="string"
                    Font-Bold="True|False"
                    Font-Italic="True|False"
                    Font-Names="string"
                    Font-Overline="True|False"
                    Font-Size="string|Smaller|Larger|XX-Small|
                        X-Small|Small|Medium|Large|X-Large|XX-Large"
                    Font-Strikeout="True|False"
                    Font-Underline="True|False"
                    ForeColor="color name|#dddddd"
                    Height="size"
                    HorizontalPadding="size"
                    ImageUrl="uri"
                    NodeSpacing="size"
                    OnDisposed="Disposed event handler"
                    VerticalPadding="size"
                    Width="size"
                />
        </LevelStyles>
        <Nodes>
                <asp:TreeNode
                    Checked="True|False"
                    Expanded="string"
                    ImageToolTip="string"
                    ImageUrl="uri"
                    NavigateUrl="uri"
                    PopulateOnDemand="True|False"
                    SelectAction="Select|Expand|SelectExpand|None"
                    Selected="True|False"
                    ShowCheckBox="string"
                    Target="string"
                    Text="string"
                    ToolTip="string"
                    Value="string"
>
                </asp:TreeNode>
        </Nodes>
        <NodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
        <ParentNodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
        <RootNodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
        <SelectedNodeStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ChildNodesPadding="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalPadding="size"
            ImageUrl="uri"
            NodeSpacing="size"
            OnDisposed="Disposed event handler"
            VerticalPadding="size"
            Width="size"
        />
</asp:TreeView>

建構函式

TreeView()

初始化 TreeView 類別的新執行個體。

屬性

AccessKey

取得或設定便捷鍵 (Access Key),可讓您快速巡覽至 Web 伺服器控制項。

(繼承來源 WebControl)
Adapter

針對控制項取得瀏覽器的特定配置器。

(繼承來源 Control)
AppRelativeTemplateSourceDirectory

取得或設定包含了此控制項之 PageUserControl 物件的相對應用程式虛擬目錄。

(繼承來源 Control)
Attributes

取得任意屬性 (Attribute) 的集合 (只供呈現),不與控制項上的屬性 (Property) 對應。

(繼承來源 WebControl)
AutoGenerateDataBindings

取得或設定值,指出 TreeView 控制項是否自動產生樹狀節點繫結。

BackColor

取得或設定 Web 伺服器控制項的背景色彩。

(繼承來源 WebControl)
BindingContainer

取得包含了此控制項之資料繫結的控制項。

(繼承來源 Control)
BorderColor

取得或設定 Web 控制項的框線色彩。

(繼承來源 WebControl)
BorderStyle

取得或設定 Web 伺服器控制項的框線樣式。

(繼承來源 WebControl)
BorderWidth

取得或設定 Web 伺服器控制項的框線寬度。

(繼承來源 WebControl)
CheckedNodes

取得 TreeNode 物件的集合,這些物件表示顯示已選取核取方塊之 TreeView 控制項中的節點。

ChildControlsCreated

取得值,指出是否已經建立伺服器控制項的子控制項。

(繼承來源 Control)
ClientID

取得 ASP.NET 所產生之 HTML 標記的控制項識別碼。

(繼承來源 Control)
ClientIDMode

取得或設定用來產生 ClientID 屬性值的演算法。

(繼承來源 Control)
ClientIDSeparator

取得字元值,表示在 ClientID 屬性中所使用的分隔字元。

(繼承來源 Control)
CollapseImageToolTip

取得或設定為可摺疊節點指示器顯示之影像的工具提示。

CollapseImageUrl

取得或設定可摺疊節點指示器之自訂影像的 URL。

Context

取得與目前 Web 要求的伺服器控制項關聯的 HttpContext 物件。

(繼承來源 Control)
Controls

取得 ControlCollection 物件,表示 UI 階層架構中指定之伺服器控制項的子控制項。

(繼承來源 Control)
ControlStyle

取得 Web 伺服器控制項的樣式。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
ControlStyleCreated

取得值,指出 Style 物件是否已經為 ControlStyle 屬性建立。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
CssClass

取得或設定用戶端上 Web 伺服器控制項所呈現的階層式樣式表 (CSS)。

(繼承來源 WebControl)
DataBindings

取得 TreeNodeBinding 物件的集合,這些物件會定義資料項目與其所繫結至的節點之間的關聯性。

DataItemContainer

如果命名容器實作 IDataItemContainer,則取得命名容器的參考。

(繼承來源 Control)
DataKeysContainer

如果命名容器實作 IDataKeysControl,則取得命名容器的參考。

(繼承來源 Control)
DataSource

取得或設定資料繫結控制項從中擷取其資料項目清單的物件。

(繼承來源 BaseDataBoundControl)
DataSourceID

取得或設定控制項的識別碼,資料繫結控制項會由此擷取其項目清單。

(繼承來源 HierarchicalDataBoundControl)
DesignMode

取得值,指出控制項是否正用於設計介面上。

(繼承來源 Control)
EnableClientScript

取得或設定值,指出 TreeView 控制項是否呈現用戶端指令碼,以處理展開和摺疊事件。

Enabled

取得或設定值,指出 Web 伺服器控制項是否啟用。

(繼承來源 WebControl)
EnableTheming

取得或設定值,指出佈景主題是否套用至此控制項。

(繼承來源 WebControl)
EnableViewState

取得或設定值,該值表示伺服器控制項是否對要求的用戶端而言保持其檢視狀態,以及它包含的任何子控制項狀態。

(繼承來源 Control)
Events

取得控制項事件處理常式委派 (Delegate) 的清單。 這個屬性是唯讀的。

(繼承來源 Control)
ExpandDepth

取得或設定第一次顯示 TreeView 控制項時展開的層級數目。

ExpandImageToolTip

取得或設定為可展開節點指示器顯示之影像的工具提示。

ExpandImageUrl

取得或設定可展開節點指示器之自訂影像的 URL。

Font

取得與 Web 伺服器控制項關聯的字型屬性。

(繼承來源 WebControl)
ForeColor

取得或設定 Web 伺服器控制項的前景色彩 (通常是文字的色彩)。

(繼承來源 WebControl)
HasAttributes

取得值,指出控制項是否已經設定屬性。

(繼承來源 WebControl)
HasChildViewState

取得值,指出目前伺服器控制項的子控制項是否有任何已儲存的檢視狀態設定。

(繼承來源 Control)
Height

取得或設定 Web 伺服器控制項的高度。

(繼承來源 WebControl)
HoverNodeStyle

取得 TreeNodeStyle 物件的參考,這個物件可讓您設定當滑鼠指標移至節點上時的節點外觀。

ID

取得或設定指派給伺服器控制項的程式設計識別項。

(繼承來源 Control)
IdSeparator

取得用來分隔控制項識別項的字元。

(繼承來源 Control)
ImageSet

取得或設定要用於 TreeView 控制項的影像群組。

Initialized

取得值,指出是否已初始化資料繫結控制項。

(繼承來源 BaseDataBoundControl)
IsBoundUsingDataSourceID

取得值,指出是否已設定 DataSourceID 屬性。

(繼承來源 BaseDataBoundControl)
IsChildControlStateCleared

取得值,指出這個控制項中所包含的控制項是否有控制項狀態。

(繼承來源 Control)
IsDataBindingAutomatic

取得值,指出資料繫結是否為自動。

(繼承來源 BaseDataBoundControl)
IsEnabled

取得值,指出是否啟用控制項。

(繼承來源 WebControl)
IsTrackingViewState

取得值,指出伺服器控制項是否正在儲存檢視狀態的變更。

(繼承來源 Control)
IsUsingModelBinders

在衍生類別中實作時,取得值,此值指出控制項是否正使用模型繫結器。

(繼承來源 BaseDataBoundControl)
IsViewStateEnabled

取得值,指出這個控制項是否已啟用檢視狀態。

(繼承來源 Control)
LeafNodeStyle

取得 TreeNodeStyle 物件的參考,這個物件可讓您設定分葉節點的外觀。

LevelStyles

取得 Style 物件的集合,表示位於樹狀結構中個別層級處的節點樣式。

LineImagesFolder

取得或設定資料夾的路徑,該資料夾包含用於將子節點連接至父節點的線條影像。

LoadViewStateByID

取得值,指出控制項是否依 ID (而不是索引) 參與載入其檢視狀態。

(繼承來源 Control)
MaxDataBindDepth

取得或設定繫結至 TreeView 控制項之樹狀層級的最大數目。

NamingContainer

取得伺服器控制項命名容器的參考,其建立唯一命名空間,在具有相同 ID 屬性值的伺服器控制項之間作區別。

(繼承來源 Control)
NodeIndent

取得或設定 TreeView 控制項之子節點的縮排量 (以像素為單位)。

Nodes

取得 TreeNode 物件的集合,表示 TreeView 控制項中的根節點。

NodeStyle

取得 TreeNodeStyle 物件的參考,這個物件可讓您設定 TreeView 控制項中節點的預設外觀。

NodeWrap

取得或設定值,指出節點空間不足時節點中的文字是否換行。

NoExpandImageUrl

取得或設定無法展開節點指示器之自訂影像的 URL。

Page

取得含有伺服器控制項的 Page 執行個體的參考。

(繼承來源 Control)
Parent

在網頁控制階層架構中取得伺服器控制項之父控制項的參考。

(繼承來源 Control)
ParentNodeStyle

取得 TreeNodeStyle 物件的參考,這個物件可讓您設定 TreeView 控制項中父節點的外觀。

PathSeparator

取得或設定字元,用於分隔 ValuePath 屬性指定的節點值。

PopulateNodesFromClient

取得或設定值,指出是否視用戶端的需要填入節點資料。

RenderingCompatibility

取得值,這個值會指定將與呈現 HTML 相容的 ASP.NET 版本。

(繼承來源 Control)
RequiresDataBinding

取得或設定值,指出是否應該呼叫 DataBind() 方法。

(繼承來源 BaseDataBoundControl)
RootNodeStyle

取得 TreeNodeStyle 物件的參考,這個物件可讓您設定 TreeView 控制項中根節點的外觀。

SelectedNode

取得 TreeNode 物件,表示 TreeView 控制項中選取的節點。

SelectedNodeStyle

取得 TreeNodeStyle 物件,其控制 TreeView 控制項中已選取節點的外觀。

SelectedValue

取得已選取節點的值。

ShowCheckBoxes

取得或設定值,指出哪些節點型別會在 TreeView 控制項中顯示核取方塊。

ShowExpandCollapse

取得或設定值,指出是否顯示展開節點指示器。

ShowLines

取得或設定值,指出是否顯示將子節點連接至父節點的線條。

Site

當呈現在設計介面上時,取得裝載目前控制項之容器的資訊。

(繼承來源 Control)
SkinID

取得或設定要套用至控制項的面板。

(繼承來源 WebControl)
SkipLinkText

取得或設定值,用於呈現替代文字,以便讓螢幕助讀員略過控制項內容。

Style

取得文字屬性的集合,將呈現為 Web 伺服器控制項的外部標記上的樣式屬性。

(繼承來源 WebControl)
SupportsDisabledAttribute

取得值,這個值表示當控制項的 disabled 屬性為 IsEnabled 時,控制項是否應該將呈現之 HTML 項目的 false 屬性設為 "disabled"。

(繼承來源 BaseDataBoundControl)
TabIndex

取得或設定 Web 伺服器控制項的定位索引。

(繼承來源 WebControl)
TagKey

取得 TreeView 控制項的 HtmlTextWriterTag 值。

TagName

取得控制項標記的名稱。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
Target

取得或設定目標視窗或框架,在其中顯示與節點關聯的 Web 網頁內容。

TemplateControl

取得或設定包含了此控制項之樣板的參考。

(繼承來源 Control)
TemplateSourceDirectory

取得包含目前伺服器控制項的 PageUserControl 的虛擬目錄。

(繼承來源 Control)
ToolTip

取得或設定當滑鼠指標停留在 Web 伺服器控制項時顯示的文字。

(繼承來源 WebControl)
UniqueID

取得伺服器控制項唯一的、符合階層架構的識別項。

(繼承來源 Control)
ValidateRequestMode

取得或設定值,指出控制項是否對來自瀏覽器的用戶端輸入檢查潛在的危險值。

(繼承來源 Control)
ViewState

取得狀態資訊的字典,允許您在相同網頁的多個要求之間,儲存和還原伺服器控制項的檢視狀態。

(繼承來源 Control)
ViewStateIgnoresCase

取得值,指出 StateBag 物件是否不區分大小寫。

(繼承來源 Control)
ViewStateMode

取得或設定這個控制項的檢視狀態模式。

(繼承來源 Control)
Visible

取得或設定值,指出控制項是否要呈現為網頁上的 UI。

Width

取得或設定 Web 伺服器控制項的寬度。

(繼承來源 WebControl)

方法

AddAttributesToRender(HtmlTextWriter)

將需要呈現的 HTML 屬性和樣式加入至指定的 HtmlTextWriter 控制項中。

AddedControl(Control, Int32)

在子控制項加入 Control 物件的 Controls 集合後呼叫。

(繼承來源 Control)
AddParsedSubObject(Object)

通知伺服器控制項,XML 或 HTML 項目已剖析,並將項目加入伺服器控制項的 ControlCollection 物件中。

(繼承來源 Control)
ApplyStyle(Style)

將指定樣式的任何非空白項目加入到 Web 控制項中,覆寫控制項的任何現有的樣式項目。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
ApplyStyleSheetSkin(Page)

將頁面樣式表中所定義的樣式屬性套用至控制項。

(繼承來源 Control)
BeginRenderTracing(TextWriter, Object)

開始進行轉譯資料的設計階段追蹤。

(繼承來源 Control)
BuildProfileTree(String, Boolean)

收集伺服器控制項的相關資訊,並在頁面啟用追蹤時將此資訊傳遞至 Trace 屬性以顯示之。

(繼承來源 Control)
ClearCachedClientID()

將快取的 ClientID 值設定為 null

(繼承來源 Control)
ClearChildControlState()

刪除伺服器控制項之子控制項的控制項狀態資訊。

(繼承來源 Control)
ClearChildState()

刪除所有伺服器控制項之子控制項的檢視狀態和控制項狀態資訊。

(繼承來源 Control)
ClearChildViewState()

刪除所有伺服器控制項之子控制項的檢視狀態資訊。

(繼承來源 Control)
ClearEffectiveClientIDMode()

將目前的控制項執行個體和任何子控制項的 ClientIDMode 屬性設定為 Inherit

(繼承來源 Control)
CollapseAll()

關閉樹狀結構中的每個節點。

ConfirmInitState()

設定資料繫結控制項之初始化的狀態。

(繼承來源 BaseDataBoundControl)
CopyBaseAttributes(WebControl)

將不被 Style 物件封裝的屬性從指定的 Web 伺服器控制項複製到呼叫這個方法的 Web 伺服器控制項上。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
CreateChildControls()

由 ASP.NET 網頁架構呼叫,通知使用組合實作的伺服器控制項來建立所包含的任何子控制項,以準備回傳或呈現。

(繼承來源 Control)
CreateControlCollection()

建立儲存子控制項的集合。

CreateControlStyle()

建立樣式物件,這個物件被 WebControl 類別內部使用,以實作所有的樣式相關屬性。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
CreateNode()

傳回 TreeNode 類別的新執行個體。 CreateNode() 為 Helper 方法。

DataBind()

呼叫基底類別的 DataBind() 方法。

DataBind(Boolean)

使用會引發 DataBinding 事件的選項,繫結資料來源至叫用的伺服器控制項及其所有子控制項。

(繼承來源 Control)
DataBindChildren()

繫結資料來源至伺服器控制項的子控制項。

(繼承來源 Control)
Dispose()

啟用伺服器控制項,在它從記憶體釋放之前執行最後清除。

(繼承來源 Control)
EndRenderTracing(TextWriter, Object)

結束轉譯資料的設計階段追蹤。

(繼承來源 Control)
EnsureChildControls()

判斷伺服器控制項是否包含子控制項。 如果不包含,則建立子控制項。

(繼承來源 Control)
EnsureDataBound()

如果設定了 DataBind() 屬性且資料繫結控制項標記為需要繫結,則會呼叫 DataSourceID 方法。

(繼承來源 BaseDataBoundControl)
EnsureID()

為尚未指定識別項的控制項,建立識別項。

(繼承來源 Control)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
ExpandAll()

開啟樹狀結構中的每個節點。

FindControl(String)

在目前命名容器搜尋具有指定 id 參數的伺服器控制項。

(繼承來源 Control)
FindControl(String, Int32)

使用指定的 id 和有助於搜尋之 pathOffset 參數中所指定的整數,在目前的命名容器中搜尋伺服器控制項。 您不應該覆寫這個版本的 FindControl 方法。

(繼承來源 Control)
FindNode(String)

擷取 TreeNode 控制項中位於指定值路徑處的 TreeView 物件。

Focus()

設定控制項的輸入焦點。

(繼承來源 Control)
GetCallbackResult()

傳回以控制項為目標之回呼事件的結果。

GetData(String)

擷取 HierarchicalDataSourceView 物件,資料繫結控制項會用來執行資料作業。

(繼承來源 HierarchicalDataBoundControl)
GetDataSource()

擷取與資料繫結控制項關聯的 IHierarchicalDataSource (如果有的話)。

(繼承來源 HierarchicalDataBoundControl)
GetDesignModeState()

取得控制項的設計階段資料。

(繼承來源 Control)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetRouteUrl(Object)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(RouteValueDictionary)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(String, Object)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。

(繼承來源 Control)
GetRouteUrl(String, RouteValueDictionary)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。

(繼承來源 Control)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetUniqueIDRelativeTo(Control)

傳回指定之控制項 UniqueID 屬性的前置部分。

(繼承來源 Control)
HasControls()

判斷伺服器控制項是否包含任何子控制項。

(繼承來源 Control)
HasEvents()

傳回值,指出控制項或任何子控制項的事件是否已註冊。

(繼承來源 Control)
IsLiteralContent()

判斷伺服器控制項是否只儲存常值內容。

(繼承來源 Control)
LoadControlState(Object)

SaveControlState() 方法所儲存的上一頁要求中,還原控制項狀態資訊。

(繼承來源 Control)
LoadPostData(String, NameValueCollection)

處理 TreeView 控制項的回傳資料。

LoadViewState(Object)

載入先前儲存的 TreeView 控制項檢視狀態。

MapPathSecure(String)

擷取虛擬絕對路徑或相對路徑所對應至的實體路徑。

(繼承來源 Control)
MarkAsDataBound()

將檢視狀態中的控制項狀態設為已成功繫結至資料。

(繼承來源 HierarchicalDataBoundControl)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MergeStyle(Style)

將指定樣式的任何非空白項目複製到 Web 控制項,但不覆寫控制項的任何現有樣式項目。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
OnBubbleEvent(Object, EventArgs)

決定伺服器控制項的事件是否要在頁面的 UI 伺服器控制項階層架構中向上傳遞。

(繼承來源 Control)
OnDataBinding(EventArgs)

引發 DataBinding 事件。

(繼承來源 Control)
OnDataBound(EventArgs)

引發 DataBound 事件。

(繼承來源 BaseDataBoundControl)
OnDataPropertyChanged()

在其中一個基底資料來源識別屬性變更時呼叫,以將資料繫結控制項重新繫結至其資料。

(繼承來源 HierarchicalDataBoundControl)
OnDataSourceChanged(Object, EventArgs)

當資料繫結控制項使用的 IHierarchicalDataSource 執行個體引發 DataSourceChanged 事件時呼叫。

(繼承來源 HierarchicalDataBoundControl)
OnInit(EventArgs)

引發 Init 事件。

OnLoad(EventArgs)

處理 Load 事件。

(繼承來源 HierarchicalDataBoundControl)
OnPagePreLoad(Object, EventArgs)

設定資料繫結控制項在載入控制項之前的初始化狀態。

(繼承來源 HierarchicalDataBoundControl)
OnPreRender(EventArgs)

引發 PreRender 事件。

OnSelectedNodeChanged(EventArgs)

引發 SelectedNodeChanged 控制項的 TreeView 事件。

OnTreeNodeCheckChanged(TreeNodeEventArgs)

引發 TreeNodeCheckChanged 控制項的 TreeView 事件。

OnTreeNodeCollapsed(TreeNodeEventArgs)

引發 TreeNodeCollapsed 控制項的 TreeView 事件。

OnTreeNodeDataBound(TreeNodeEventArgs)

引發 TreeNodeDataBound 控制項的 TreeView 事件。

OnTreeNodeExpanded(TreeNodeEventArgs)

引發 TreeNodeExpanded 控制項的 TreeView 事件。

OnTreeNodePopulate(TreeNodeEventArgs)

引發 TreeNodePopulate 控制項的 TreeView 事件。

OnUnload(EventArgs)

引發 Unload 事件。

(繼承來源 Control)
OpenFile(String)

取得用來讀取檔案的 Stream

(繼承來源 Control)
PerformDataBinding()

依據資料來源建立所有節點。

PerformSelect()

從關聯的資料來源擷取資料。

(繼承來源 HierarchicalDataBoundControl)
RaiseBubbleEvent(Object, EventArgs)

指派事件的任何來源和它的資訊至控制項的父控制項。

(繼承來源 Control)
RaiseCallbackEvent(String)

使用指定的引數引發回呼事件。

RaisePostBackEvent(String)

啟用 TreeView 控制項,以處理當表單回傳至伺服器時引發的事件。 RaisePostBackEvent(String) 方法是 ICallbackEventHandler.RaiseCallbackEvent(String) 方法的 Helper 方法。

RaisePostDataChangedEvent()

通知 TreeView 控制項應告知 ASP.NET 應用程式,控制項的狀態已變更。

RemovedControl(Control)

Control 物件的 Controls 集合中移除子控制項之後呼叫。

(繼承來源 Control)
Render(HtmlTextWriter)

將控制項呈現在指定的 HTML 寫入器中。

(繼承來源 WebControl)
RenderBeginTag(HtmlTextWriter)

將控制項的 HTML 開頭標記呈現在指定的寫入器中。

RenderChildren(HtmlTextWriter)

將伺服器控制項子系的內容輸出至提供的 HtmlTextWriter 物件,再由這個物件在用戶端上寫入要轉譯的內容。

(繼承來源 Control)
RenderContents(HtmlTextWriter)

TreeView 控制項中呈現節點。

RenderControl(HtmlTextWriter)

將伺服器控制項內容輸出至提供的 HtmlTextWriter 物件,並在啟用追蹤時儲存控制項的追蹤資訊。

(繼承來源 Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 物件,輸出伺服器控制項內容至提供的 ControlAdapter 物件。

(繼承來源 Control)
RenderEndTag(HtmlTextWriter)

將控制項的 HTML 結尾標記呈現至指定的寫入器。

ResolveAdapter()

取得負責呈現指定之控制項的控制項配置器。

(繼承來源 Control)
ResolveClientUrl(String)

取得瀏覽器可使用的 URL。

(繼承來源 Control)
ResolveUrl(String)

將 URL 轉換為要求用戶端可使用的 URL。

(繼承來源 Control)
SaveControlState()

儲存頁面回傳至伺服器以來,所發生的任何伺服器控制項狀態變更。

(繼承來源 Control)
SaveViewState()

儲存 TreeView 控制項的狀態。

SetDesignModeState(IDictionary)

設定控制項的設計階段資料。

(繼承來源 Control)
SetNodeDataBound(TreeNode, Boolean)

允許衍生類別設定指定的 TreeNode 控制項是否為資料繫結。

SetNodeDataItem(TreeNode, Object)

允許衍生類別設定指定 TreeNode 控制項的資料項目。

SetNodeDataPath(TreeNode, String)

允許衍生類別設定指定 TreeNode 控制項的資料路徑。

SetRenderMethodDelegate(RenderMethod)

指定事件處理常式委派,以呈現伺服器控制項及其內容至其父控制項。

(繼承來源 Control)
SetTraceData(Object, Object)

使用追蹤資料機碼和追蹤資料值,設定設計階段期間追蹤呈現資料的追蹤資料。

(繼承來源 Control)
SetTraceData(Object, Object, Object)

使用追蹤的物體、追蹤資料機碼和追蹤資料值,設定設計階段期間追蹤呈現資料的追蹤資料。

(繼承來源 Control)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
TrackViewState()

追蹤 TreeView 控制項的檢視狀態變更,讓這些變更能夠儲存在控制項的 StateBag 物件中。 這個 StateBag 可透過 ViewState 屬性存取。

ValidateDataSource(Object)

驗證資料繫結控制項繫結至的物件是該資料繫結控制項所使用的物件。

(繼承來源 HierarchicalDataBoundControl)

事件

DataBinding

發生於伺服器控制項繫結至資料來源時。

(繼承來源 Control)
DataBound

在伺服器控制項繫結至資料來源之後發生。

(繼承來源 BaseDataBoundControl)
Disposed

發生於伺服器控制項從記憶體釋放時,這是在要求 ASP.NET 網頁時,伺服器控制項生命週期的最後階段。

(繼承來源 Control)
Init

發生於初始化伺服器控制項時,是其生命週期中的第一個步驟。

(繼承來源 Control)
Load

發生於載入伺服器控制項至 Page 物件時。

(繼承來源 Control)
PreRender

Control 物件載入之後但在呈現之前發生。

(繼承來源 Control)
SelectedNodeChanged

當在 TreeView 控制項中選取節點時就會發生。

TreeNodeCheckChanged

TreeView 控制項的核取方塊在張貼至伺服器之間變更狀態時發生。

TreeNodeCollapsed

當在 TreeView 控制項中摺疊節點時就會發生。

TreeNodeDataBound

當資料項目繫結至 TreeView 控制項中的節點時就會發生。

TreeNodeExpanded

當在 TreeView 控制項中展開節點時就會發生。

TreeNodePopulate

當在 PopulateOnDemand 控制項中展開 TreeView 屬性設為 true 的節點時發生。

Unload

發生於伺服器控制項從記憶體卸載時。

(繼承來源 Control)

明確介面實作

IAttributeAccessor.GetAttribute(String)

使用指定的名稱,取得 Web 控制項的屬性。

(繼承來源 WebControl)
IAttributeAccessor.SetAttribute(String, String)

將 Web 控制項的屬性設定為指定的名稱和值。

(繼承來源 WebControl)
ICallbackEventHandler.GetCallbackResult()

傳回以控制項為目標之回呼事件的結果。

ICallbackEventHandler.RaiseCallbackEvent(String)

使用指定的引數引發回呼事件。

IControlBuilderAccessor.ControlBuilder

如需這個成員的說明,請參閱 ControlBuilder

(繼承來源 Control)
IControlDesignerAccessor.GetDesignModeState()

如需這個成員的說明,請參閱 GetDesignModeState()

(繼承來源 Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

如需這個成員的說明,請參閱 SetDesignModeState(IDictionary)

(繼承來源 Control)
IControlDesignerAccessor.SetOwnerControl(Control)

如需這個成員的說明,請參閱 SetOwnerControl(Control)

(繼承來源 Control)
IControlDesignerAccessor.UserData

如需這個成員的說明,請參閱 UserData

(繼承來源 Control)
IDataBindingsAccessor.DataBindings

如需這個成員的說明,請參閱 DataBindings

(繼承來源 Control)
IDataBindingsAccessor.HasDataBindings

如需這個成員的說明,請參閱 HasDataBindings

(繼承來源 Control)
IExpressionsAccessor.Expressions

如需這個成員的說明,請參閱 Expressions

(繼承來源 Control)
IExpressionsAccessor.HasExpressions

如需這個成員的說明,請參閱 HasExpressions

(繼承來源 Control)
IParserAccessor.AddParsedSubObject(Object)

如需這個成員的說明,請參閱 AddParsedSubObject(Object)

(繼承來源 Control)
IPostBackDataHandler.LoadPostData(String, NameValueCollection)

處理 TreeView 控制項的回傳資料。

IPostBackDataHandler.RaisePostDataChangedEvent()

通知 TreeView 控制項應告知 ASP.NET 應用程式,控制項的狀態已變更。

IPostBackEventHandler.RaisePostBackEvent(String)

啟用 TreeView 控制項,以處理當表單回傳至伺服器時引發的事件。

擴充方法

EnablePersistedSelection(BaseDataBoundControl)
已淘汰.

啟用要保存於資料控制項中且支援選取和分頁的選項。

FindDataSourceControl(Control)

傳回與指定之控制項的資料控制項相關聯的資料來源。

FindFieldTemplate(Control, String)

傳回在指定之控制項的命名容器中所指定資料行的欄位樣板。

FindMetaTable(Control)

傳回包含資料控制項的中繼資料表物件。

適用於

另請參閱