System.Web.UI.WebControls Namespace TreeView Class
.NET Framework version 2.0
Returns the value of the selected node in a TreeView control.
Script |
[ String strValue = ] TreeView.SelectedValue |
This property can only be used programmatically; it cannot be set when declaring the control.
strValue |
The value of the selected node in a TreeView control. |
The property is read only with no default value.
Use the SelectedValue property to determine the value of the selected node in a TreeView control.
This property simply returns the value of the Value property of the TreeNode object that is referred to by the SelectedNode property ( SelectedNode.Value ).
If no Value is specified for the node, this property returns the value of the selected node's Text property. If the Text property in turn contains a null reference, or if no node is currently selected in the TreeView control, an empty string ( "" ) is returned.
To access other properties of the selected node, though, such as Parent or Depth, you still need to use the SelectedNode property.
The following example demonstrates how to use the SelectedValue property to determine the value of the selected node in a TreeView control.
message.Text = "Selected TreeNode Value: " + myTreeView.SelectedValue;
message.Text = "Selected TreeNode Value: " + myTreeView.SelectedValue |
|
C# |
VB |
Show me
TreeView Members SelectedNode Text Value