TreeNode Konstruktory

Definice

Inicializuje novou instanci TreeNode třídy.

Přetížení

TreeNode()

Inicializuje novou instanci TreeNode třídy bez textu nebo hodnoty.

TreeNode(String)

Inicializuje novou instanci TreeNode třídy pomocí zadaného textu.

TreeNode(String, String)

Inicializuje novou instanci TreeNode třídy pomocí zadaného textu a hodnoty.

TreeNode(TreeView, Boolean)

Inicializuje novou instanci TreeNode třídy pomocí zadaného vlastníka.

TreeNode(String, String, String)

Inicializuje novou instanci TreeNode třídy pomocí zadaného textu, hodnoty a adresy URL obrázku.

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

Inicializuje novou instanci třídy pomocí zadaného TreeNode textu, hodnoty, adresy URL obrázku, navigační adresy URL a cíle.

TreeNode()

Inicializuje novou instanci TreeNode třídy bez textu nebo hodnoty.

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

Příklady

Následující příklad kódu ukazuje použití tohoto konstruktoru k dynamickému přidání uzlu do TreeView ovládacího prvku.


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

Poznámky

Pomocí tohoto konstruktoru TreeNode inicializujete novou instanci třídy pomocí výchozích hodnot.

Poznámka

Při použití tohoto konstruktoru jsou všechny vlastnosti v objektu TreeNode nastaveny na jejich výchozí hodnoty. Po vytvoření objektu nezapomeňte podle potřeby nastavit vlastnosti.

Viz také

Platí pro

TreeNode(String)

Inicializuje novou instanci TreeNode třídy pomocí zadaného textu.

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

Text zobrazený v ovládacím TreeView prvku uzlu.

Příklady

Následující příklad kódu ukazuje použití tohoto konstruktoru k dynamickému přidání uzlu do TreeView ovládacího prvku.


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

Poznámky

Pomocí tohoto konstruktoru TreeNode inicializujete novou instanci třídy pomocí textu určeného parametrem text .

V následující tabulce je uvedena počáteční hodnota vlastnosti instance TreeNode.

Vlastnost Počáteční hodnota
Text Hodnota parametru text .

Viz také

Platí pro

TreeNode(String, String)

Inicializuje novou instanci TreeNode třídy pomocí zadaného textu a hodnoty.

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

Text zobrazený v ovládacím TreeView prvku uzlu.

value
String

Doplňková data přidružená k uzlu, jako jsou data používaná pro zpracování událostí postback.

Příklady

Následující příklad kódu ukazuje použití tohoto konstruktoru k dynamickému přidání uzlu do TreeView ovládacího prvku.


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

Poznámky

Pomocí tohoto konstruktoru TreeNode můžete inicializovat novou instanci třídy pomocí textu a hodnoty určené parametry text a value v uvedeném pořadí.

V následující tabulce jsou uvedeny počáteční hodnoty vlastností instance TreeNode.

Vlastnost Počáteční hodnota
Text Hodnota parametru text .
Value Hodnota parametru value .

Viz také

Platí pro

TreeNode(TreeView, Boolean)

Inicializuje novou instanci TreeNode třídy pomocí zadaného vlastníka.

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

Ta TreeView bude obsahovat nový TreeNode.

isRoot
Boolean

trueTreeNode pokud je kořenový uzel; v opačném případě false.

Viz také

Platí pro

TreeNode(String, String, String)

Inicializuje novou instanci TreeNode třídy pomocí zadaného textu, hodnoty a adresy URL obrázku.

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

Text zobrazený v ovládacím TreeView prvku uzlu.

value
String

Doplňková data přidružená k uzlu, jako jsou data používaná pro zpracování událostí postback.

imageUrl
String

Adresa URL obrázku, který se zobrazí vedle uzlu.

Příklady

Následující příklad kódu ukazuje použití tohoto konstruktoru k dynamickému přidání uzlu do TreeView ovládacího prvku.


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

Poznámky

Pomocí tohoto konstruktoru TreeNode můžete inicializovat novou instanci třídy pomocí textu, hodnoty a adresy URL obrázku určené parametrem text, valuea imageUrl parametry v uvedeném pořadí.

V následující tabulce jsou uvedeny počáteční hodnoty vlastností instance TreeNode.

Vlastnost Počáteční hodnota
Text Hodnota parametru text .
Value Hodnota parametru value .
ImageUrl Hodnota parametru imageUrl .

Viz také

Platí pro

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

Inicializuje novou instanci třídy pomocí zadaného TreeNode textu, hodnoty, adresy URL obrázku, navigační adresy URL a cíle.

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

Text zobrazený v ovládacím TreeView prvku uzlu.

value
String

Doplňková data přidružená k uzlu, jako jsou data používaná pro zpracování událostí postback.

imageUrl
String

Adresa URL obrázku, který se zobrazí vedle uzlu.

navigateUrl
String

Adresa URL, na která se má odkazovat po kliknutí na uzel.

target
String

Cílové okno nebo rámec, ve kterém se má zobrazit obsah webové stránky propojený po kliknutí na uzel.

Příklady

Následující příklad kódu ukazuje použití tohoto konstruktoru k dynamickému přidání uzlu do TreeView ovládacího prvku.


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

Poznámky

Pomocí tohoto konstruktoru TreeNode můžete inicializovat novou instanci třídy pomocí textu, hodnoty, obrázku a navigačních adres URL a zobrazit cíl určený parametrem text, , value``imageUrl, navigateUrl, a target parametry v uvedeném pořadí.

V následující tabulce jsou uvedeny počáteční hodnoty vlastností instance TreeNode.

Vlastnost Počáteční hodnota
Text Hodnota parametru text .
Value Hodnota parametru value .
ImageUrl Hodnota parametru imageUrl .
NavigateUrl Hodnota parametru navigateUrl .
Target Hodnota parametru target .

Viz také

Platí pro