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

How to Get Node Value and Set Selected by Node Value in Treeview

1 Answer 167 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Brijendra Kumar
Top achievements
Rank 1
Brijendra Kumar asked on 15 Dec 2008, 12:53 PM
Hi All,

I have a treeview control in my page.
This is like as follows:

    Value is in []

    AAAA [1]
        aaa [1]
              BBB [1]
              BBB [2]
              BBB [3]
        aaa [2]
        aaa [3]
        aaa [4]


I have to find node "BBB" whose value is "3". Does anybody know then plz tell me how to get and set selected using Javascript.

Thanks in advance....

Regards
Brijendra Pandey

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 16 Dec 2008, 12:48 PM
Hello Brijendra Kumar,

You can use a helper JavaScript routine:

function FindNodeByTextAndValue(treeView, text, value)
{
 
 var allNodes = treeView.get_allNodes();
 for (var i = 0; i < allNodes.length;i++)
 {
    var node = allNodes[i];
    if (node.get_text() == text && node.get_value() == value)
      return node;
 }
 
 return null;
}

And here is how to use it:

var treeView = $find("<%= RadTreeView1.ClientID %>");
var myNode = FindNodeByTextAndValue(treeView, "BBB", "3");
if (myNode)
  myNode.select();

All the best,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Brijendra Kumar
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or