System.Web.UI.WebControls Namespace TreeNode Class
.NET Framework version 2.0
Sets or retrieves the text displayed for a TreeNode in a TreeView control.
Inline |
<asp:treenode text = strtext ... > |
Script |
TreeNode.Text [ = strtext ] |
strtext |
String that specifies the text displayed for a node in a TreeView control. |
The property is read/write with no default value.
Use the Text property to specify or determine the text to display for a TreeNode in a TreeView control.
In certain cases, such as when a TreeView control is bound to a data source, the Text property is usually obtained dynamically from the data source.
The following example shows how to declaratively set the Text property of tree nodes at design time.
<asp:treenode text = "News">
Show me
The following example shows how to programmatically set the Text property of tree nodes at run time.
TreeNode newNode = new TreeNode ( newNodeText, newNodeValue );
myTreeView.Nodes.Add ( newNode );
Dim newNode As New TreeNode ( newNodeText, newNodeValue )
myTreeView.Nodes.Add ( newNode ) |
|
C# |
VB |
Show me
The following example demonstrates how to programmatically determine the given Text for a node and its parent, when the user selects an item from a TreeView control.
TreeNode selectedNode = myTreeView.SelectedNode;
message.Text = "Selected TreeNode Text: " + selectedNode.Text;
Dim selectedNode As TreeNode = myTreeView.SelectedNode
message.Text = "Selected TreeNode Text: " + selectedNode.Text |
|
C# |
VB |
Note that this example merely serves to illustrate the concept. If all you need is to determine the selected node's Text, simply use the SelectedNode.Text property instead, without having to code a handler for the SelectedNodeChanged event.
Show me
TreeNode Members Value SelectedValue