views:

1313

answers:

1

I have a RadTreeView on a MasterPage inside 2 nested RadSplitters. I am using LoadOnDemand, but need to be able to expand nodes from serverside code. I am attempting to do this by calling the method I have written to expand the node to the ResponseScripts. This method is in a RadCodeBlock as follows:

<telerik:RadCodeBlock ID="RadCodeBlock2" runat="server"> 
<script type="text/javascript"> 
    function expandNode(nodeid) { 
        var treeView = $find("<%= NavigationTreeView.ClientID %>"); 
        var node = treeView.findNodeByValue(nodeid); 
        if (node) { 
            node.expand(); 
            return true; 
        } 
        return false; 
    }    
</script> 
</telerik:RadCodeBlock>

My problem is that I am not able to access the RadTreeView to expand the nodes. I would appreciate any guidance on how to access this treeview from javascript using $find.

Thanks!

Lauren Kirschner

+1  A: 

Hey Lauren,

If you try and expand the tree view from javascript, the code you have works fine.

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

function expandNode(nodeid) {

                var treeView = $find("<%= NavigationTreeView.ClientID %>");         
                var node = treeView.findNodeByValue(nodeid);
                alert(node);
                if (node) 
                {             
                    node.expand();             
                    return true;         
                }



                return false; 



            }

        </script>
    </telerik:RadCodeBlock>

    <telerik:RadSplitter ID="RadSplitter1" runat="server">
        <telerik:RadPane ID="RadPane" runat="server">
            <telerik:RadTreeView ID="NavigationTreeView" runat="server" >
                <Nodes>
                    <telerik:RadTreeNode Text="Node 1" Value="0">
                        <Nodes>
                            <telerik:RadTreeNode Text="Child1" Value="1"></telerik:RadTreeNode>
                        </Nodes>
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeView>
        </telerik:RadPane>
    </telerik:RadSplitter>

    <asp:Button ID="BtnExpand" runat="server" Text="Expand jscript" OnClientClick="expandNode(0);" />
    <asp:Button ID="BtnExpandServer" runat="server" Text="Expand Server" OnClick="BtnExpandServer_Click" />

    <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

    </asp:ContentPlaceHolder>
</div>
</form>

If you are trying to expand server side, the following works based on the example I posted above.

protected void BtnExpandServer_Click(object sender, EventArgs e)
{        
    RadTreeNode node = NavigationTreeView.FindNodeByValue("0");
    node.Expanded = true;
}
kf

related questions