Expand childnodes by button or link button click

4 posts, 0 answers
  1. Vittal
    Vittal avatar
    2 posts
    Member since:
    Jun 2012

    Posted 12 Jun 2012 Link to this post

    Hi,
    we are not able to expand all the child nodes when we click on separate asp button or link button.
    we are using Visual Studio 2008.
    we are using datasource to load the treeview. we will have three levels of child nodes and all these levels should expand when we click the Expand All Button/Link Button.
    we have implemented the expandall functionality from javascript.after this event OnNodeExpand server side will be triggered so here we are binding all the child to parents and also we are setting the expanded property is set to TRUE to all the nodes.

    so after this postback event the rad treeview gets refreshed and we are losing the expand all.

    Telerik Web.Design and Telerik.Web.UI Version : 2009.2.701.20
    ASP.NET:
     <asp:Button ID="btnExpand" runat="server" Text="Expand All" OnClick="btnExpand_Click" />

    <telerik:RadTreeView ID="RadTreeView4" runat="server" OnNodeExpand="RadTreeView4_NodeExpand">
                </telerik:RadTreeView>
    C#:
    protected void Page_Load(object sender, EventArgs e)
            {
                try
                {
                    if (!IsPostBack)
                    {
                        DataView dtParent = (DataView)SessionDataSource1.Select(DataSourceSelectArguments.Empty);
                        foreach (DataRowView drvParent in dtParent)
                        {
                            rootNode = new RadTreeNode(drvParent["AICategoryName"].ToString());
                            rootNode.Text = rootNode.Text;
                            rootNode.Expanded = true;
                            rootNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
                            RadTreeView4.Nodes.Add(rootNode);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            protected void RadTreeView4_NodeExpand(object sender, RadTreeNodeEventArgs e)
            {
                ExpandNode(e.Node);
            }

            protected void ExpandNode(RadTreeNode e)
            {
                DataView dtChild = (DataView)SessionDataSource2.Select(DataSourceSelectArguments.Empty);
                foreach (DataRowView drvChild in dtChild)
                {
                    rootNode = null;
                    rootNode = new RadTreeNode(drvChild["AILevel1Name"].ToString());
                    rootNode.Text = rootNode.Text;
                    RadTreeView4.ExpandAllNodes();
                    e.Nodes[0].Expanded = true;
                    e.Nodes.Add(rootNode);
                    
                }            
            }
    Javascript:
    function ExpandAll()
        {alert('call');
            var treeView = $find("<%= trTaxonomy.ClientID %>");
            var nodes = treeView.get_allNodes();
            for (var i = 0; i < nodes.length; i++) {
                if (nodes[i].get_nodes() != null) {
                    nodes[i].expand();
                }
            }
        }
  2. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 13 Jun 2012 Link to this post

    Hello Vittal,

    If you want to load all remaining child nodes in the treeview, the LoadOnDemand functionality wouldn't be of much help to you. It is designed to populate only the children of a single node. In your case, where you want to populate the whole threeview, I suggest that you attach a Click event to the link button and in this event you can load all the nodes of the tree.
     
    Greetings,
    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
  4. Vittal
    Vittal avatar
    2 posts
    Member since:
    Jun 2012

    Posted 13 Jun 2012 Link to this post

    Hi

    I've tried expanding all the Nodes from Javascript using ClientOnClick event of the Link button.

    Now the Tree expands, but we have OnNodeExpand event to bind the Child for all the Parents. So after the OnNodeExpand event finishes it execution, the tree gets refreshed and the expanded Tree colapses.

    OnNodeExpand breaks the ExpandAll that we are trying from client side. So please check and let us know how we can resolve this issue.

    Thanks
    Vittal
  5. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 14 Jun 2012 Link to this post

    Hello Vittal,

    Could you open a support ticket and attach a runnable sample project demonstrating the issue, so that I can test it locally to get a better understanding of the problem. You can use the following article as a guideline when creating the sample project:
    http://blogs.telerik.com/aspnet-ajax/posts/10-09-29/isolating-a-problem-in-a-sample-project.aspx 
     
    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.
Back to Top