System.Web.UI.WebControls Namespace TreeView Class
.NET Framework version 2.0
Occurs when a node is selected in a TreeView control.
[ VB ]
Public Event SelectedNodeChanged As EventHandler
[ C# ]
public event EventHandler SelectedNodeChanged;
[ C++ ]
public: __event EventHandler* SelectedNodeChanged;
In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
The SelectedNodeChanged event is raised whenever a node is selected in a TreeView control.
This allows you to provide an event-handling method that performs a custom routine, such as updating the displayed TreeView content, whenever this event occurs.
You can optionally set the SelectAction property for a node to specify which event is raised whenever that node is selected. The following table lists the available options.
Selection action |
Description |
Expand |
Toggles the node between expanded and collapsed. Raises the TreeNodeExpanded or TreeNodeCollapsed event, as appropriate. |
None |
Raises no events when a node is selected. |
Select |
Raises the SelectedNodeChanged event when a node is selected. |
SelectExpand |
Raises both the SelectedNodeChanged and TreeNodeExpanded events when a node is selected. Nodes are only expanded, never collapsed. |
NOTE: The HoverNodeStyle is not rendered for a node with its SelectAction property set to TreeNodeSelectAction.None.
The SelectedNodeChanged event is fired only on post back when a user clicks a node. The event is not fired if the SelectedNode property is changed programmatically.
The following example demonstrates how to specify and code a handler for the SelectedNodeChanged event.
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.";
}
<asp:treeview id = "myTreeView" runat = "server"
...
onSelectedNodeChanged = "getSelectedValues" />
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
<asp:treeview id = "myTreeView" runat = "server"
...
onSelectedNodeChanged = "getSelectedValues" /> |
|
C# |
VB |
Show me
TreeView Members