How to add CheckBox in TreeView Control Using ASP.Net 2.0
Download Source Code : 285_TreeViewControl.zip
In this article I will try to explain you how you can add CheckBox in TreeView control. Here I will create a very simple program that adds the nodes to TreeView Control dynamically.
Microsoft .Net Framework 2.0 has added many new features like classes, controls etc. Among these new features you will find a new addition to navigational controls. Add the new addition in this control is TreeView control that allows you to display your data in hierarchal way. For example you want to display your directory contents on your browser; this TreeView Control can be helpful you in displaying data. Similarly, there are many other uses for displaying data on a browser using TreeView Control.
TreeView control has many features e.g. you can bind TreeView control with XMLDataSource or you have auto format option that allow you to show TreeView control in your own way. TreeView control also allows you to display CheckBox either on Parent node or on Leaf Node or to all nodes i.e. Parent Node as well as Leaf Node. In following example I have created a TreeView Control programmatically having CheckBox on each leaf node and on the button click event a message is displayed on the browser that shows which child node you have selected of which parent. Code Snippet for this example is as follows:
On the Page_Load event and cmdCheckSelectNode_Click event add the following code:
Note you can display your messages using String Builder. Using this approach means String Builder is more efficient.