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

add text label on nodes

2 Answers 42 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rubihno
Top achievements
Rank 1
Rubihno asked on 04 Dec 2008, 01:17 PM
Hi,

I populate my treeview to code behind, with sql tables, i would you like to add on nodes the label....

For example

- Users
  -   Andy (word)    <- nodes
  -   Micheal (word)  <- nodes

The name of the node are in colum table, but the label (word) is not the db values, i would you like to add this label for example, when i generate the treeview....

How i make? in code behind make this?
 

2 Answers, 1 is accepted

Sort by
0
Serrin
Top achievements
Rank 1
answered on 04 Dec 2008, 03:08 PM
Hey Rubihno,

Alright, two parts to this answer. :)

First, you could modify the text as follows:

    protected void RadTreeView1_NodeCreated(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)  
    {  
       e.Node.Text = e.Node.Text + " (word)";  
    }  

That works and puts (word) after all nodes...  The trick is...

Second part, figuring out if the node is one that should get the (word)...  My first idea was to check level (aka, root is 0, everything else is a child of root:

        if (e.Node.Level > 0)  
        {  
            e.Node.Text = e.Node.Text + " (word)";  
        } 

So you can play with e.Node to see if it fits some category... like maybe you have root/topics/kids, so then you would do if level > 1, etc.

Let me know if this works for you! 

0
Rubihno
Top achievements
Rank 1
answered on 05 Dec 2008, 12:01 PM
Thanks a lot, it is easy...:)


Tags
TreeView
Asked by
Rubihno
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
Rubihno
Top achievements
Rank 1
Share this question
or