System.Web.UI.WebControls Namespace TreeNode Class
.NET Framework version 2.0
Returns the parent TreeNode of the current node.
Script |
[ TreeNode node = ] TreeNode.Parent |
This property can only be used programmatically; it cannot be set when declaring the control.
node |
A TreeNode object that represents the parent of the current node. |
The property is read only with no default value.
Use the Parent property to determine the parent of the current node or to access the parent node's properties.
NOTE: A root node does not have a parent node.
To access the subnodes of the current node, use the ChildNodes property.
The following example demonstrates how to use the Parent property to access the properties of the current node's parent node.
void getSelectedValues ( Object source, EventArgs e ) {
TreeNode selectedNode = myTreeView.SelectedNode;
message.Text = "Selected TreeNode Text: <b>" + selectedNode.Text + "</b><br>" +
"Selected TreeNode Value: <b>" + myTreeView.SelectedValue + "</b>";
if ( selectedNode.Parent != null )
message.Text += "<p>Selected TreeNode's Parent Text: <b>" + selectedNode.Parent.Text + "</b><br>" +
"Selected TreeNode's Parent Value: <b>" + selectedNode.Parent.Value + "</b>";
else
message.Text += "<p>The selected item is a root menu item that does not have a parent.";
}
Sub getSelectedValues ( source As Object, e As EventArgs )
Dim selectedNode As TreeNode = myTreeView.SelectedNode
message.Text = "Selected TreeNode Text: <b>" + selectedNode.Text + "</b><br>" +
"Selected TreeNode Value: <b>" + myTreeView.SelectedValue + "</b>"
If Not ( selectedNode.Parent Is Nothing ) Then
message.Text += "<p>Selected TreeNode's Parent Text: <b>" + selectedNode.Parent.Text + "</b><br>" +
"Selected TreeNode's Parent Value: <b>" + selectedNode.Parent.Value + "</b>"
Else
message.Text += "<p>The selected item is a root menu item that does not have a parent."
End If
End Sub |
|
C# |
VB |
Show me
TreeNode Members