asp.net.ph

TreeNode.Value Property

System.Web.UI.WebControls Namespace   TreeNode Class


.NET Framework version 2.0

Sets or retrieves the value associated with a TreeNode.

Syntax


Inline <asp:treenode value = strValue ... >
Script TreeNode.Value = strValue

Property Value


strValue The value associated with a TreeNode.

The property is read/write with no default value.

Remarks

Use the Value property to specify or determine the value associated with a TreeNode.

The Value property is used to supplement the Text property by storing any additional data associated with the node. This value is not displayed in the control and is commonly used to store data that is to be passed on to the appropriate event handler on postback.

NOTE: If no Value is specified for the node, this property returns the value of the Text property. If the Text property in turn contains a null reference, an empty string is returned.

The value of the Value property is also used when the ValuePath property is generated. A value path is a delimiter-separated list of node values that forms a path from the root node to the current node. The value path is used to indicate the position of a node in a TreeView control.

NOTE: Nodes at the same level must each have a unique value for the Value property; the TreeView control cannot distinguish between different nodes at the same level that have the same value.

In certain cases, such as when a TreeView control is bound to a data source, the Value property is usually obtained dynamically from the data source.

Example

The following example shows how to programmatically set the Value property of tree nodes at run time.

TreeNode newNode = new TreeNode ( newNodeText, newNodeValue );
myTreeView.Nodes.Add ( newNode );
  C# VB

 Show me 

The following example demonstrates how to programmatically determine the given Value for a node and its parent, when the user selects an item from a TreeView control.

TreeNode selectedNode = myTreeView.SelectedNode;
message.Text = "Selected TreeNode Value: " + selectedNode.Value;
  C# VB

Note that this example merely serves to illustrate the concept. If all you need is to determine the selected node's Value, simply use the TreeView.SelectedValue property instead, without having to code a handler for the SelectedNodeChanged event.

 Show me 

See Also

TreeNode Members   Text   SelectedValue Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph