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

5 posts, 0 answers
  1. Sandeep
    Sandeep avatar
    3 posts
    Member since:
    Feb 2013

    Posted 25 Feb 2013 Link to this post

    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())));
    }
  2. Sandeep
    Sandeep avatar
    3 posts
    Member since:
    Feb 2013

    Posted 27 Feb 2013 Link to this post

    Hi All,

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

    --
    Thanks and Regards
    Sandeep
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 27 Feb 2013 Link to this post

    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.
  5. Sandeep
    Sandeep avatar
    3 posts
    Member since:
    Feb 2013

    Posted 01 Mar 2013 Link to this post

    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

  6. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 05 Mar 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017