TreeView Expand Programmatically Fails to Show any nodes

2 posts, 0 answers
  1. Eric Caslake
    Eric Caslake avatar
    4 posts
    Member since:
    Dec 2009

    Posted 30 Dec 2009 Link to this post

    I have a TreeView that has ExpandMode set to WebService and I would like to expand a node programmatically. I have even tried to emulate this is some client side code and I can see the web service call being made and returning data. However, the node does not expand as desired.

                String.prototype.endsWith = function(str){return (this.match(str+"$")==str)} 
                function nodeChecked(sender, eventArgs) { 
                    var node = eventArgs.get_node(); 
                    var parent = node.get_parent(); 
                    var grand_parent = parent.get_parent();    
                    var parent_value = parent.get_value(); 
                    var parent_value_other = ""
                    if (parent_value.endsWith("cc")) { 
                        parent_value_other = parent_value.substring(0, parent_value.length - 2) 
                        var tree = $find("<%= RadTreeView1.ClientID %>"); 
                        var other_node = tree.findNodeByValue(parent_value_other); 
                        if (other_node.get_expanded() == false) { 
                        var other_node_array = other_node.get_nodes(); 
                        for (var i = 0; i < other_node_array.get_count(); i++) { 
                            var _node = other_node_array.getNode(i); 
                            if (_node.get_text() == node.get_text()) { 

    No matter what happens, the following line always shows the number of items in the list as 0.

    var other_node_array = other_node.get_nodes();  

    What am I doing wrong?


    Is there something I can try to make this work client side?
  2. Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 05 Jan 2010 Link to this post

    Hi Eric Caslake,

    You need to move this code:

    var other_node_array = other_node.get_nodes();
                        for (var i = 0; i < other_node_array.get_count(); i++) {
                            var _node = other_node_array.getNode(i);
                            if (_node.get_text() == node.get_text()) {

    to the handler of the OnClientNodePopulated event. This will ensure that the child nodes are already added.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top