This is a migrated thread and some comments may be shown as answers.

Adding root node from code behind.

1 Answer 157 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Naupad
Top achievements
Rank 1
Naupad asked on 17 Jan 2012, 07:58 PM
I am having a RadTreeView that is binded to a LINQ datasource. Now my treeview gets loaded with all values I want. But I want to show all these items to be appearing under a root node: "ROOT" that I can set programatically or statically.

How to do this?

Also if I have a column called "tooltip" in my LINQ datasource whose value I want to show as a tool-tip to the nodes of the tree-view than how to achieve this?

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 20 Jan 2012, 04:14 PM
Hi Naupad,

Here is the code, which I added to our Linq Demo and it worked at my side:

protected void Page_Load(object sender, EventArgs e)
   {
       RadTreeView1.DataBind();
 
       RadTreeNode root = new RadTreeNode("Root");
 
       while (RadTreeView1.Nodes.Count > 0)
       {
           root.Nodes.Add(RadTreeView1.Nodes[0]);
       }
 
       RadTreeView1.Nodes.Add(root);
   }
   protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
   {
       string tooltip = (string)DataBinder.Eval(e.Node.DataItem, "Text");
       e.Node.ToolTip = tooltip;
   }

Hope it will be helpful.

Kind regards,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
TreeView
Asked by
Naupad
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or