Selection, Navigation, and Check Boxes in the TreeView Web Server Control
The ASP.NETcontrol makes it easy for you to respond when a user clicks a node, or to change the behavior of a node to make it act like a hyperlink. Additionally, you can use the TreeView control to display check boxes next to individual nodes so that users can select multiple nodes at once.
Selection and Navigation
Each node has aproperty and a property. The value of the Text property is displayed in the TreeView control, while the Value property is used to store any additional data about the node, such as data passed to the postback event that is associated with the node.
When a node of the TreeView control is clicked, it can either raise a selection event (via postback) or go to another page. When the NavigateUrl property is not set, clicking a node will raise aevent that can be handled to provide custom functionality. You can also check the property of a node to determine whether it is selected. Setting this property to true or calling the method on the node will cause the node to be selected programmatically.
Each node also has aproperty that can be used to specify actions that will occur when the node is clicked, such as expanding or collapsing the node. Instead of raising a SelectedNodeChanged event to go to another page when a node is clicked, set the NavigateUrl property of the node to a value other than an empty string ("").
For more information about handling selection events, see. For more information about navigation mode, see . For more information about setting the NavigateUrl property when binding data, see .
In cases where you want users to be able to select multiple nodes, you can use the TreeView control to display a check box next to a node image. When theproperty is set to a TreeNodeType other than TreeNodeType.None, check boxes are displayed next to the specified nodes. When check boxes are displayed, you can use the event to run your custom routine whenever the state of a check box changes between posts to the server. The next time the page is posted to the server, the property is populated with the selected nodes.
The TreeView control does not expose anproperty. Thus, to submit check box selections, you must place a control, such as a Web server control, on the page to post information back to the server.
For more information about using check boxes with the ASP.NET TreeView control, see.