TreeNode Constructor (String, String, String, String, String)
Initializes a new instance of the TreeNode class using the specified text, value, image URL, navigation URL, and target.
Assembly: System.Web (in System.Web.dll)
public TreeNode( string text, string value, string imageUrl, string navigateUrl, string target )
Parameters
- text
-
Type:
System.String
The text that is displayed in the TreeView control for the node.
- value
-
Type:
System.String
The supplemental data associated with the node, such as data used for handling postback events.
- imageUrl
-
Type:
System.String
The URL to an image that is displayed next to the node.
- navigateUrl
-
Type:
System.String
The URL to link to when the node is clicked.
- target
-
Type:
System.String
The target window or frame in which to display the Web page content linked to when the node is clicked.
Use this constructor to initialize a new instance of the TreeNode class using the text, value, image and navigation URLs, and display target specified by the text, value, imageUrl, navigateUrl, and target parameters, respectively.
The following table shows initial property values for an instance of TreeNode.
Property | Initial value |
|---|---|
The value of the text parameter. | |
The value of the value parameter. | |
The value of the imageUrl parameter. | |
The value of the navigateUrl parameter. | |
The value of the target parameter. |
The following code example demonstrates how to use this constructor to dynamically add a node to the TreeView control.
<%@ 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>
Available since 2.0