This is a migrated thread and some comments may be shown as answers.

Expand/Collapse and Highlighted Selected Node using C# (programmatically)

4 Answers 372 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Sandeep
Top achievements
Rank 1
Sandeep asked on 25 Feb 2013, 08:52 AM
Hi All,

I am using Telerik RadTreeview control for the navigation purpose in DotNetNuke (DNN) custom module. Below is the look and feel of the RadTreeview control on my portal and RadTreeview control displayed on each and every page of the portal.

First time when ever page get loaded its display as below though Page 2 and Page 5 contains sub-pages

Page 1
Page 2
Page 3
Page 4
Page 5

What I want is if I click on Page 2.1 then it will redirect to page Page 2.1 (which is working fine)  and the RadTreeview control will display as below on page Page 2.1.

Page 1
Page 2
     Page 2.1
     Page 2.2
Page 3
Page 4
Page 5

After that if I click on Page 5.2 then it will redirect to page Page 5.2 (which is working fine)  and the RadTreeview control will display as below on page Page 5.2.

Page 1
Page 2
Page 3
Page 4
Page 5
     Page 5.1
     Page 5.2

After that if I click on Page 4 then it will redirect to page Page 4 (which is working fine)  and the RadTreeview control will display as below on page Page 4.

Page 1
Page 2
Page 3
Page 4
Page 5

I mean the selected page's parent should be in expand mode and the selected page should be highlighted.

Kindly let me know how we can achieve this functionality through programmatically.

Below is the code what I have with me right now.

.ASCX Code

<telerik:RadTreeView ID="RadTreeView1" runat="server" OnNodeClick="RadTreeView1_NodeClick" Skin="NGR"  EnableEmbeddedSkins="false" ShowLineImages="false">
    <databindings>
        <telerik:RadTreeNodeBinding Expanded="False"></telerik:RadTreeNodeBinding>
    </databindings>
</telerik:RadTreeView>


C# Code


protected void Page_Load(object sender, EventArgs e)
{
            if (!Page.IsPostBack)
            {
                BindLeftNavigation(RadTreeView1);
            }
}
 
private void BindLeftNavigation(RadTreeView treeView)
{
            MenuController objController = new MenuController();
 
            DataSet ds = new DataSet();
 
            ds = objController.Get_Menu(this.PortalId);
 
            if (ds.Tables[0].Rows.Count > 0)
            {
                treeView.DataSource = ds;
                treeView.DataTextField = "TabName";
                treeView.DataValueField = "TabID";
                treeView.DataNavigateUrlField = "";
                treeView.DataFieldID = "TabID";
                treeView.DataFieldParentID = "ParentID";
                treeView.DataBind();
            }
}
 
protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
{
        Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(Convert.ToInt32(e.Node.Value.ToString())));
}

4 Answers, 1 is accepted

Sort by
0
Sandeep
Top achievements
Rank 1
answered on 27 Feb 2013, 07:18 AM
Hi All,

Anyone expert in Telerik RadTreeview control. So kindly guide me how can I fix the mentioned issue ?

--
Thanks and Regards
Sandeep
0
Bozhidar
Telerik team
answered on 27 Feb 2013, 09:33 AM
Hi Sandeep,

You can set the ExpandParentNodes method. I've attached a simple page demonstrating how you can expand the treeview to a specific node and select it from code behind.
 

All the best,
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.
0
Sandeep
Top achievements
Rank 1
answered on 01 Mar 2013, 12:15 PM
Hi Bozhidar,

Thanks for the response.

I tried your solution but its not working as per the expectation. I am still facing the same issue. I am using RadTreeview in DNN custom module and this module call on each and every page of the DNN portal.

As its calling on every page due to this its creating an issue ?

Kindly let me know asap.

--
Thanks and Regards

Sandeep

0
Bozhidar
Telerik team
answered on 05 Mar 2013, 08:51 AM
Hi Sandeep,

Since you are creating the TreeView on every page you have to store the selected node in a Session variable or somewhere else, and then manually expand the Tree to that node on each page load using the method from my previous reply.
 

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.
Tags
TreeView
Asked by
Sandeep
Top achievements
Rank 1
Answers by
Sandeep
Top achievements
Rank 1
Bozhidar
Telerik team
Share this question
or