TreeNode 생성자

정의

TreeNode 클래스의 새 인스턴스를 초기화합니다.

오버로드

TreeNode()

텍스트나 값을 사용하지 않고 TreeNode 클래스의 새 인스턴스를 초기화합니다.

TreeNode(String)

지정된 텍스트를 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

TreeNode(String, String)

지정된 텍스트와 값을 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

TreeNode(TreeView, Boolean)

지정된 소유자를 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

TreeNode(String, String, String)

지정된 텍스트, 값 및 이미지 URL을 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

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

지정된 텍스트, 값, 이미지 URL, 탐색 URL 및 대상을 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

TreeNode()

텍스트나 값을 사용하지 않고 TreeNode 클래스의 새 인스턴스를 초기화합니다.

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

예제

다음 코드 예제에서는 노드를 동적으로 추가 하려면이 생성자를 사용 하는 방법에 설명 합니다 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>

설명

새 인스턴스를 초기화 하려면이 생성자를 사용 합니다 TreeNode 클래스 기본값을 사용 합니다.

참고

이 생성자를 사용 하는 경우, 모든 속성에는 TreeNode 개체가 기본값으로 설정 됩니다. 개체를 만든 후 필요에 따라 속성을 설정 해야 합니다.

추가 정보

적용 대상

TreeNode(String)

지정된 텍스트를 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

text
String

TreeView 컨트롤에서 노드에 대해 표시되는 텍스트입니다.

예제

다음 코드 예제에서는 노드를 동적으로 추가 하려면이 생성자를 사용 하는 방법에 설명 합니다 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>

설명

새 인스턴스를 초기화 하려면이 생성자를 사용 합니다 TreeNode 하 여 지정 된 텍스트를 사용 하 여 클래스를 text 매개 변수입니다.

다음 표에서 인스턴스에 대 한 초기 속성 값을 TreeNode입니다.

속성 초기 값
Text text 매개 변수의 값입니다.

추가 정보

적용 대상

TreeNode(String, String)

지정된 텍스트와 값을 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

text
String

TreeView 컨트롤에서 노드에 대해 표시되는 텍스트입니다.

value
String

포스트백 이벤트를 처리하는 데 사용되는 데이터 같이 노드와 연결된 추가 데이터입니다.

예제

다음 코드 예제에서는 노드를 동적으로 추가 하려면이 생성자를 사용 하는 방법에 설명 합니다 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>

설명

새 인스턴스를 초기화 하려면이 생성자를 사용 합니다 TreeNode 텍스트 및 지정 된 값을 사용 하 여 클래스를 textvalue 매개 변수를 각각.

다음 표에서 인스턴스에 대 한 초기 속성 값을 보여 줍니다. TreeNode합니다.

속성 초기 값
Text text 매개 변수의 값입니다.
Value value 매개 변수의 값입니다.

추가 정보

적용 대상

TreeNode(TreeView, Boolean)

지정된 소유자를 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

owner
TreeView

TreeView가 포함될 TreeNode입니다.

isRoot
Boolean

TreeNode가 루트 노드이면 true이고, 그렇지 않으면 false입니다.

추가 정보

적용 대상

TreeNode(String, String, String)

지정된 텍스트, 값 및 이미지 URL을 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

text
String

TreeView 컨트롤에서 노드에 대해 표시되는 텍스트입니다.

value
String

포스트백 이벤트를 처리하는 데 사용되는 데이터 같이 노드와 연결된 추가 데이터입니다.

imageUrl
String

노드 옆에 표시되는 이미지의 URL입니다.

예제

다음 코드 예제에서는 노드를 동적으로 추가 하려면이 생성자를 사용 하는 방법에 설명 합니다 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>

설명

새 인스턴스를 초기화 하려면이 생성자를 사용 합니다 TreeNode 텍스트, 값을 사용 하 여 클래스 및 지정 된 URL 이미지를 textvalue, 및 imageUrl 매개 변수를 각각.

다음 표에서 인스턴스에 대 한 초기 속성 값을 보여 줍니다. TreeNode합니다.

속성 초기 값
Text text 매개 변수의 값입니다.
Value value 매개 변수의 값입니다.
ImageUrl imageUrl 매개 변수의 값입니다.

추가 정보

적용 대상

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

지정된 텍스트, 값, 이미지 URL, 탐색 URL 및 대상을 사용하여 TreeNode 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

text
String

TreeView 컨트롤에서 노드에 대해 표시되는 텍스트입니다.

value
String

포스트백 이벤트를 처리하는 데 사용되는 데이터 같이 노드와 연결된 추가 데이터입니다.

imageUrl
String

노드 옆에 표시되는 이미지의 URL입니다.

navigateUrl
String

노드를 클릭할 때 링크되는 URL입니다.

target
String

노드를 클릭할 때 링크되는 웹 페이지 콘텐츠를 표시할 대상 창 또는 프레임입니다.

예제

다음 코드 예제에서는 노드를 동적으로 추가 하려면이 생성자를 사용 하는 방법에 설명 합니다 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>

설명

새 인스턴스를 초기화 하려면이 생성자를 사용 합니다 TreeNode 텍스트, 값, 이미지 및 탐색 Url을 사용 하 여 클래스 및 대상으로 지정 된 표시 합니다 text, value, imageUrl, navigateUrl, 및 target 매개 변수를 각각.

다음 표에서 인스턴스에 대 한 초기 속성 값을 보여 줍니다. TreeNode합니다.

속성 초기 값
Text text 매개 변수의 값입니다.
Value value 매개 변수의 값입니다.
ImageUrl imageUrl 매개 변수의 값입니다.
NavigateUrl navigateUrl 매개 변수의 값입니다.
Target target 매개 변수의 값입니다.

추가 정보

적용 대상