Using the server-side API, you can programmatically add, remove, and edit nodes in Telerik RadTreeView.
Below is the code used to programmatically build a treeview with three root nodes that have one child node each:
| C# |
Copy Code |
|
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { RadTreeNode root1 = new RadTreeNode("root1"); RadTreeNode child1 = new RadTreeNode("child1"); root1.Nodes.Add(child1); RadTreeView1.Nodes.Add(root1);
RadTreeNode root2 = new RadTreeNode("root2"); RadTreeNode child2 = new RadTreeNode("child2"); root2.Nodes.Add(child2); RadTreeView1.Nodes.Add(root2);
RadTreeNode root3 = new RadTreeNode("root3"); RadTreeNode child3 = new RadTreeNode("child3"); root3.Nodes.Add(child3); RadTreeView1.Nodes.Add(root3); } } |
| VB.NET |
Copy Code |
|
Protected Sub Page_Load(sender As Object, e As EventArgs) If Not Page.IsPostBack Then Dim root1 As New RadTreeNode("root1") Dim child1 As New RadTreeNode("child1") root1.Nodes.Add(child1) RadTreeView1.Nodes.Add(root1)
Dim root2 As New RadTreeNode("root2") Dim child2 As New RadTreeNode("child2") root2.Nodes.Add(child2) RadTreeView1.Nodes.Add(root2)
Dim root3 As New RadTreeNode("root3") Dim child3 As New RadTreeNode("child3") root3.Nodes.Add(child3) RadTreeView1.Nodes.Add(root3) End If End Sub
|
The result of the above code will be:

 |
-
All RadTreeNodes have an attribute called Parent containing an instance to the parent RadTreeNode (if any) or null if the parent is the RadTreeView itself (i.e. this node is a root).
-
All RadTreeNodes have an attribute called TreeView containing an instance to the parent RadTreeView. |
See Also