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

2 posts, 0 answers
  1. Brijendra Kumar
    Brijendra Kumar avatar
    38 posts
    Member since:
    Oct 2008

    Posted 15 Dec 2008 Link to this post

    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....

    Brijendra Pandey
  2. Atanas Korchev
    Atanas Korchev avatar
    8462 posts

    Posted 16 Dec 2008 Link to this post

    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);

    All the best,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top