The TreeView control is an object model in ASP.Net that allows the creation of nodes dynamically. It will have a Root, Parent, and Leaf.
The TreeView control has properties and events. It has some characteristics.
- TreeView node can navigate to some other pages.
- The images and properties can be set to the nodes.
- It can have lines, checkboxes,es, and images.
- It can set dynamically expand/collapse.
- The nodes can be created on demand.
The sample treeview code.
<asp:TreeView ID="TreeView1" runat="server">
<Nodes>
<asp:TreeNode Value="Child1" PopulateOnDemand="true" ShowCheckBox="true" Expanded="True" Text="1">
<asp:TreeNode Value="Grandchild1" Text="A" />
<asp:TreeNode Value="Grandchild2" Text="B" />
</asp:TreeNode>
<asp:TreeNode Value="Child2" Text="2" />
<asp:TreeNode Value="Child3" Expanded="True" Text="3">
<asp:TreeNode Value="Grandchild1" Text="A" />
</asp:TreeNode>
</Nodes>
</asp:TreeView>
There are some properties that are useful for defining the behavior of the TreeView. These properties are Boolean value-based.
- PopulateOnDemand: It will populate the node under another node on demand. It will help to increase the performance; it would not create and render at the time of initial loading.
- ShowCheckBox: This property is used to set whether the checkbox is required or not.
- Expand: It accepts Boolean property to set the node has to be expanded or collapsed at the time of rendering.
- ShowLines: This is used to show the flow of the nodes in the lines.
Let's see an example of the SQL Server TreeView. It will show all the databases in the given SQL Server.
The databases are the parent nodes. All the databases have child nodes like Tables, Views, Stored procedures, Triggers, and Functions.
Every table in the database will have a list of tables underlying the database.
Click on every table will show the schema of the table.
Please download the code attachment, change your SQL Server connection string, and check out the code.