Find a dataitem to expand in radtreelist

3 posts, 1 answers
  1. Patrick
    Patrick avatar
    20 posts
    Member since:
    Feb 2008

    Posted 10 Mar 2011 Link to this post

    I have a radtreelist where I expose my webpage hierarchie. When I select a pageitem  in the tree i will be navigated to a webpage where I can edit this pageitem. After saving the changes I will be navigated back to my the with the radtreelist. What I want is to expand the treeitem I have just edited. So actually restoring the collapse-view like it was before I was navigated to the editpage.

    How can I retrieve the dataitem in the treeview basewd on the DataKeyName.

    Does anybody has an example how to accomplish this.

    Thanks

    Patrick
  2. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 11 Mar 2011 Link to this post

    Hello Patrick,

    You need to save the RadTreeList.ExpandedIndexes collection before navigating away from the treelist page. You can save it in Session for example. When returning back, you can restore this collection to RadTreeList to preserve the expanded item state. You only need to make sure RadTreeList is databound to the same data after returning back. If you bind it to another data source, the indexes will be invalid.

    To save the expanded indexes, you can use the PreRender event of the page or the control. Loading happens on initial load:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            var expandedIndexes = Session["ExpandedIndexes"] as TreeListExpandedIndexesCollection;
            if (expandedIndexes != null)
            {
                RadTreeList1.ExpandedIndexes.AddRange(expandedIndexes);
            }
        }
    }
     
    protected void Page_PreRender(object sender, EventArgs e)
    {
        Session["ExpandedIndexes"] = RadTreeList1.ExpandedIndexes;
    }

    The above code preserves the expanded indexes of RadTreeList1 even if you navigate away from the page and then come back.

    Veli
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Patrick
    Patrick avatar
    20 posts
    Member since:
    Feb 2008

    Posted 12 Mar 2011 Link to this post

    Thanks. This I also like using Telerik. Good controls and good and quick answers.

    Thx
Back to Top