NODEEXPAND property Problem

2 posts, 0 answers
  1. Xorv
    Xorv avatar
    19 posts
    Member since:
    Jan 2012

    Posted 11 Jan 2012 Link to this post

    Hi Admin,

    I want to fire RadTreeView to expand and load data, to nodes dynamically and automatically. When I use normal asp.net tree view and its property ''PopulateOnDemand" and set 'OnTreeNodePopulate' to fire a function, it does the pupose.
    ASPX:-
    <
    asp:TreeView Runat="Server" OnTreeNodePopulate="Node_Populate" ID="treeView1"  OnTreeNodeExpanded="Node_Expand">
     
    <Nodes>
     
    <asp:TreeNode Text="ALL"  PopulateOnDemand= "true" Value="0"  />
     
    </Nodes>
     
    </asp:TreeView>


    CS file:-

    public
    void Node_Populate(object sender, System.Web.UI.WebControls.TreeNodeEventArgs e)
        {
            if (e.Node.ChildNodes.Count == 0)
            {
                switch (e.Node.Depth)
                {
                    case 0:
                        FillTerritories(e.Node);
                        break;
                    case 1:
                        FillOrganizations(e.Node);
                        break;
                    case 2:
                        FillOffices(e.Node);
                        break;
                }
            }
        }
    So when the page loades,TreeView loades with a root node ("ALL") and hence forth, due to 'PopulateOnDemand' property its node gets fired(clicked), calling 'Node_Populate' function to handle the loading of nodes.


    Now, THE QUESTION. Same thing I want in telerik. I already tried what documentation is available here and suggestion by experts here.
    the is:- telerik property 'OnNodeExpand' fires only when a node is clicked by someone. I want to populate node automatically from root node itself. So please help what to do in this regard.

    Here is what I have tried:-
    ASPX File
    <telerik:RadTreeView Runat="Server" ID="RadTreeView1" Skin="Vista" OnNodeExpand = "Rad_NodeExpand" >
    </telerik:RadTreeView>

    CS FILE
    protected void Rad_NodeExpand(object sender, RadTreeNodeEventArgs e)
        {
            if (e.Node.Nodes.Count == 0)
            {
                switch (e.Node.Level)
                {
                    case 0:
                        FillTerritories(e.Node);
                        break;
                    case 1:
                        FillOrganizations(e.Node);
                        break;
                    case 2:
                        FillOffices(e.Node);
                        break;
                }
            }
        }


         PLEASE DON'T REFER ME ANY DOCUMENT. SEE IF YOU CAN GET MY PROBLEM.

    Thanks a lot

     

     

  2. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 13 Jan 2012 Link to this post

    Hi Sourav,

    If I understand you correctly, you want to automatically trigger the load on demand from the root node when the tree is loaded. To accomplish that, you can use the set_expanded() client method of the node. Here's a small example:
    <telerik:RadTreeView OnNodeExpand="RadTreeView1_NodeExpand" OnClientLoad="clientLoad" ID="RadTreeView1" runat="server">
        <Nodes>
            <telerik:RadTreeNode Text="root" ExpandMode="ServerSideCallBack" />
        </Nodes>
    </telerik:RadTreeView>
    <script type="text/javascript">
                
        function clientLoad(sender) {
            var tree = sender;
            var rootNode = sender.get_nodes().getNode(0);
            rootNode.set_expanded(true);
        }
     
    </script>


    Kind regards,
    Bozhidar
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top