TreeNode 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 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)
参数
示例
下面的代码示例演示如何使用此构造函数将节点 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>
注解
使用此构造函数使用参数指定的text
文本初始化类的新实例TreeNode。
下表显示了实例 TreeNode的初始属性值。
properties | 初始值 |
---|---|
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)
参数
- 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>
注解
使用此构造函数可分别使用由text
和value
参数指定的文本和值初始化类的新实例TreeNode。
下表显示了实例 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)
参数
另请参阅
适用于
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)
参数
- 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>
注解
使用此构造函数可分别使用由 text``value
和参数指定的文本、值和imageUrl
图像 URL 初始化类的新实例TreeNode。
下表显示了实例 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)
参数
- 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>
注解
使用此构造函数使用文本、值、图像和导航 URL 初始化类的新实例TreeNode,以及分别由 text
、、value
、 imageUrl``navigateUrl
和target
参数指定的显示目标。
下表显示了实例 TreeNode的初始属性值。
属性 | 初始值 |
---|---|
Text | text 参数的值。 |
Value | value 参数的值。 |
ImageUrl | imageUrl 参数的值。 |
NavigateUrl | navigateUrl 参数的值。 |
Target | target 参数的值。 |