TreeNode Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy TreeNode.

Przeciążenia

TreeNode()

Inicjuje TreeNode nowe wystąpienie klasy bez tekstu lub wartości.

TreeNode(String)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego tekstu.

TreeNode(String, String)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego tekstu i wartości.

TreeNode(TreeView, Boolean)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego właściciela.

TreeNode(String, String, String)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego tekstu, wartości i adresu URL obrazu.

TreeNode(String, String, String, String, String)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego tekstu, wartości, adresu URL obrazu, adresu URL nawigacji i elementu docelowego.

TreeNode()

Inicjuje TreeNode nowe wystąpienie klasy bez tekstu lub wartości.

public:
 TreeNode();
public TreeNode ();
Public Sub New ()

Przykłady

W poniższym przykładzie kodu pokazano, jak używać tego konstruktora do dynamicznego dodawania węzła do kontrolki TreeView .


<%@ 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_Init(Object sender, EventArgs e)
  {
  
    if(!IsPostBack)
    {

      // Add the first tree to the TreeView control.
      CreateTree("Section 1");

      // Add the second tree to the TreeView control.
      CreateTree("Section 2");
    
    }

  }

  void CreateTree(String NodeText)
  {

    // Create the root node using the default constructor.
    TreeNode root = new TreeNode();
    root.Text = NodeText;

    // Use the ChildNodes property of the root TreeNode to add child nodes.
    // Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(new TreeNode("Topic 1"));

    // Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2"));

    // Create the node using the constructor that takes the text, value, 
    // and imageUrl parameters.
    root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg"));

    // Create the node using the constructor that takes the text, value, 
    // imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"));

    // Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root);

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </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">
<script runat="server">

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

    If Not IsPostBack Then

      ' Add the first tree to the TreeView control.
      CreateTree("Section 1")

      ' Add the second tree to the TreeView control.
      CreateTree("Section 2")

    End If

  End Sub

  Sub CreateTree(ByVal NodeText As String)

    ' Create the root node using the default constructor.
    Dim root As TreeNode = New TreeNode
    root.Text = NodeText

    ' Use the ChildNodes property of the root TreeNode to add child nodes.
    ' Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(New TreeNode("Topic 1"))

    ' Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2"))

    ' Create the node using the constructor that takes the text, value, 
    ' and imageUrl parameters.
    root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg"))

    ' Create the node using the constructor that takes the text, value, 
    ' imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"))

    ' Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root)

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </asp:TreeView>

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

Uwagi

Użyj tego konstruktora, aby zainicjować nowe wystąpienie klasy przy użyciu wartości domyślnych TreeNode .

Uwaga

Gdy ten konstruktor jest używany, wszystkie właściwości w TreeNode obiekcie są ustawione na wartości domyślne. Pamiętaj, aby ustawić właściwości zgodnie z potrzebami po utworzeniu obiektu.

Zobacz też

Dotyczy

TreeNode(String)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego tekstu.

public:
 TreeNode(System::String ^ text);
public TreeNode (string text);
new System.Web.UI.WebControls.TreeNode : string -> System.Web.UI.WebControls.TreeNode
Public Sub New (text As String)

Parametry

text
String

Tekst wyświetlany w kontrolce TreeView węzła.

Przykłady

W poniższym przykładzie kodu pokazano, jak używać tego konstruktora do dynamicznego dodawania węzła do kontrolki TreeView .


<%@ 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_Init(Object sender, EventArgs e)
  {
  
    if(!IsPostBack)
    {

      // Add the first tree to the TreeView control.
      CreateTree("Section 1");

      // Add the second tree to the TreeView control.
      CreateTree("Section 2");
    
    }

  }

  void CreateTree(String NodeText)
  {

    // Create the root node using the default constructor.
    TreeNode root = new TreeNode();
    root.Text = NodeText;

    // Use the ChildNodes property of the root TreeNode to add child nodes.
    // Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(new TreeNode("Topic 1"));

    // Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2"));

    // Create the node using the constructor that takes the text, value, 
    // and imageUrl parameters.
    root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg"));

    // Create the node using the constructor that takes the text, value, 
    // imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"));

    // Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root);

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </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">
<script runat="server">

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

    If Not IsPostBack Then

      ' Add the first tree to the TreeView control.
      CreateTree("Section 1")

      ' Add the second tree to the TreeView control.
      CreateTree("Section 2")

    End If

  End Sub

  Sub CreateTree(ByVal NodeText As String)

    ' Create the root node using the default constructor.
    Dim root As TreeNode = New TreeNode
    root.Text = NodeText

    ' Use the ChildNodes property of the root TreeNode to add child nodes.
    ' Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(New TreeNode("Topic 1"))

    ' Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2"))

    ' Create the node using the constructor that takes the text, value, 
    ' and imageUrl parameters.
    root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg"))

    ' Create the node using the constructor that takes the text, value, 
    ' imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"))

    ' Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root)

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </asp:TreeView>

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

Uwagi

Użyj tego konstruktora, aby zainicjować nowe wystąpienie TreeNode klasy przy użyciu tekstu określonego text przez parametr .

W poniższej tabeli przedstawiono początkową wartość właściwości dla wystąpienia klasy TreeNode.

Właściwość Wartość początkowa
Text Wartość parametru text .

Zobacz też

Dotyczy

TreeNode(String, String)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego tekstu i wartości.

public:
 TreeNode(System::String ^ text, System::String ^ value);
public TreeNode (string text, string value);
new System.Web.UI.WebControls.TreeNode : string * string -> System.Web.UI.WebControls.TreeNode
Public Sub New (text As String, value As String)

Parametry

text
String

Tekst wyświetlany w kontrolce TreeView węzła.

value
String

Dane uzupełniające skojarzone z węzłem, takie jak dane używane do obsługi zdarzeń zwrotnych.

Przykłady

W poniższym przykładzie kodu pokazano, jak używać tego konstruktora do dynamicznego dodawania węzła do kontrolki TreeView .


<%@ 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_Init(Object sender, EventArgs e)
  {
  
    if(!IsPostBack)
    {

      // Add the first tree to the TreeView control.
      CreateTree("Section 1");

      // Add the second tree to the TreeView control.
      CreateTree("Section 2");
    
    }

  }

  void CreateTree(String NodeText)
  {

    // Create the root node using the default constructor.
    TreeNode root = new TreeNode();
    root.Text = NodeText;

    // Use the ChildNodes property of the root TreeNode to add child nodes.
    // Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(new TreeNode("Topic 1"));

    // Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2"));

    // Create the node using the constructor that takes the text, value, 
    // and imageUrl parameters.
    root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg"));

    // Create the node using the constructor that takes the text, value, 
    // imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"));

    // Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root);

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </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">
<script runat="server">

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

    If Not IsPostBack Then

      ' Add the first tree to the TreeView control.
      CreateTree("Section 1")

      ' Add the second tree to the TreeView control.
      CreateTree("Section 2")

    End If

  End Sub

  Sub CreateTree(ByVal NodeText As String)

    ' Create the root node using the default constructor.
    Dim root As TreeNode = New TreeNode
    root.Text = NodeText

    ' Use the ChildNodes property of the root TreeNode to add child nodes.
    ' Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(New TreeNode("Topic 1"))

    ' Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2"))

    ' Create the node using the constructor that takes the text, value, 
    ' and imageUrl parameters.
    root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg"))

    ' Create the node using the constructor that takes the text, value, 
    ' imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"))

    ' Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root)

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </asp:TreeView>

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

Uwagi

Użyj tego konstruktora, aby zainicjować nowe wystąpienie TreeNode klasy przy użyciu tekstu i wartości określonej odpowiednio przez text parametry i value .

W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia klasy TreeNode.

Właściwość Wartość początkowa
Text Wartość parametru text .
Value Wartość parametru value .

Zobacz też

Dotyczy

TreeNode(TreeView, Boolean)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego właściciela.

protected public:
 TreeNode(System::Web::UI::WebControls::TreeView ^ owner, bool isRoot);
protected internal TreeNode (System.Web.UI.WebControls.TreeView owner, bool isRoot);
new System.Web.UI.WebControls.TreeNode : System.Web.UI.WebControls.TreeView * bool -> System.Web.UI.WebControls.TreeNode
Protected Friend Sub New (owner As TreeView, isRoot As Boolean)

Parametry

owner
TreeView

Element TreeView , który będzie zawierać nowy TreeNodeelement .

isRoot
Boolean

true jeśli element TreeNode jest węzłem głównym; w przeciwnym razie false.

Zobacz też

Dotyczy

TreeNode(String, String, String)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego tekstu, wartości i adresu URL obrazu.

public:
 TreeNode(System::String ^ text, System::String ^ value, System::String ^ imageUrl);
public TreeNode (string text, string value, string imageUrl);
new System.Web.UI.WebControls.TreeNode : string * string * string -> System.Web.UI.WebControls.TreeNode
Public Sub New (text As String, value As String, imageUrl As String)

Parametry

text
String

Tekst wyświetlany w kontrolce TreeView węzła.

value
String

Dane uzupełniające skojarzone z węzłem, takie jak dane używane do obsługi zdarzeń zwrotnych.

imageUrl
String

Adres URL obrazu wyświetlanego obok węzła.

Przykłady

W poniższym przykładzie kodu pokazano, jak używać tego konstruktora do dynamicznego dodawania węzła do kontrolki TreeView .


<%@ 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_Init(Object sender, EventArgs e)
  {
  
    if(!IsPostBack)
    {

      // Add the first tree to the TreeView control.
      CreateTree("Section 1");

      // Add the second tree to the TreeView control.
      CreateTree("Section 2");
    
    }

  }

  void CreateTree(String NodeText)
  {

    // Create the root node using the default constructor.
    TreeNode root = new TreeNode();
    root.Text = NodeText;

    // Use the ChildNodes property of the root TreeNode to add child nodes.
    // Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(new TreeNode("Topic 1"));

    // Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2"));

    // Create the node using the constructor that takes the text, value, 
    // and imageUrl parameters.
    root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg"));

    // Create the node using the constructor that takes the text, value, 
    // imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"));

    // Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root);

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </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">
<script runat="server">

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

    If Not IsPostBack Then

      ' Add the first tree to the TreeView control.
      CreateTree("Section 1")

      ' Add the second tree to the TreeView control.
      CreateTree("Section 2")

    End If

  End Sub

  Sub CreateTree(ByVal NodeText As String)

    ' Create the root node using the default constructor.
    Dim root As TreeNode = New TreeNode
    root.Text = NodeText

    ' Use the ChildNodes property of the root TreeNode to add child nodes.
    ' Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(New TreeNode("Topic 1"))

    ' Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2"))

    ' Create the node using the constructor that takes the text, value, 
    ' and imageUrl parameters.
    root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg"))

    ' Create the node using the constructor that takes the text, value, 
    ' imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"))

    ' Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root)

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </asp:TreeView>

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

Uwagi

Użyj tego konstruktora, aby zainicjować nowe wystąpienie TreeNode klasy przy użyciu odpowiednio adresu URL tekstu, wartości i obrazu określonego textprzez parametry , valuei imageUrl .

W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia klasy TreeNode.

Właściwość Wartość początkowa
Text Wartość parametru text .
Value Wartość parametru value .
ImageUrl Wartość parametru imageUrl .

Zobacz też

Dotyczy

TreeNode(String, String, String, String, String)

Inicjuje TreeNode nowe wystąpienie klasy przy użyciu określonego tekstu, wartości, adresu URL obrazu, adresu URL nawigacji i elementu docelowego.

public:
 TreeNode(System::String ^ text, System::String ^ value, System::String ^ imageUrl, System::String ^ navigateUrl, System::String ^ target);
public TreeNode (string text, string value, string imageUrl, string navigateUrl, string target);
new System.Web.UI.WebControls.TreeNode : string * string * string * string * string -> System.Web.UI.WebControls.TreeNode
Public Sub New (text As String, value As String, imageUrl As String, navigateUrl As String, target As String)

Parametry

text
String

Tekst wyświetlany w kontrolce TreeView węzła.

value
String

Dane uzupełniające skojarzone z węzłem, takie jak dane używane do obsługi zdarzeń zwrotnych.

imageUrl
String

Adres URL obrazu wyświetlanego obok węzła.

navigateUrl
String

Adres URL, z którym chcesz połączyć się po kliknięciu węzła.

target
String

Okno docelowe lub ramka, w której ma być wyświetlana zawartość strony sieci Web połączona po kliknięciu węzła.

Przykłady

W poniższym przykładzie kodu pokazano, jak używać tego konstruktora do dynamicznego dodawania węzła do kontrolki TreeView .


<%@ 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_Init(Object sender, EventArgs e)
  {
  
    if(!IsPostBack)
    {

      // Add the first tree to the TreeView control.
      CreateTree("Section 1");

      // Add the second tree to the TreeView control.
      CreateTree("Section 2");
    
    }

  }

  void CreateTree(String NodeText)
  {

    // Create the root node using the default constructor.
    TreeNode root = new TreeNode();
    root.Text = NodeText;

    // Use the ChildNodes property of the root TreeNode to add child nodes.
    // Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(new TreeNode("Topic 1"));

    // Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2"));

    // Create the node using the constructor that takes the text, value, 
    // and imageUrl parameters.
    root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg"));

    // Create the node using the constructor that takes the text, value, 
    // imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"));

    // Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root);

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </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">
<script runat="server">

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

    If Not IsPostBack Then

      ' Add the first tree to the TreeView control.
      CreateTree("Section 1")

      ' Add the second tree to the TreeView control.
      CreateTree("Section 2")

    End If

  End Sub

  Sub CreateTree(ByVal NodeText As String)

    ' Create the root node using the default constructor.
    Dim root As TreeNode = New TreeNode
    root.Text = NodeText

    ' Use the ChildNodes property of the root TreeNode to add child nodes.
    ' Create the node using the constructor that takes the text parameter.
    root.ChildNodes.Add(New TreeNode("Topic 1"))

    ' Create the node using the constructor that takes the text and value parameters.
    root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2"))

    ' Create the node using the constructor that takes the text, value, 
    ' and imageUrl parameters.
    root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg"))

    ' Create the node using the constructor that takes the text, value, 
    ' imageUrl, navigateUrl, and target parameters.
    root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank"))

    ' Add the root node to the Nodes collection of the TreeView control.
    DynamicTreeView.Nodes.Add(root)

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNode Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNode Constructor Example</h3>
      
      <asp:TreeView id="DynamicTreeView"
         EnableClientScript="false"
         ExpandDepth="2" 
         runat="server">
        
      </asp:TreeView>

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

Uwagi

Użyj tego konstruktora, aby zainicjować nowe wystąpienie TreeNode klasy przy użyciu odpowiednio tekstu, wartości, obrazów i adresów URL nawigacji oraz wyświetlić obiekt docelowy określony odpowiednio przez textparametry , value, imageUrl, navigateUrli target .

W poniższej tabeli przedstawiono początkowe wartości właściwości dla wystąpienia klasy TreeNode.

Właściwość Wartość początkowa
Text Wartość parametru text .
Value Wartość parametru value .
ImageUrl Wartość parametru imageUrl .
NavigateUrl Wartość parametru navigateUrl .
Target Wartość parametru target .

Zobacz też

Dotyczy