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

Find a dataitem to expand in radtreelist

2 Answers 179 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 10 Mar 2011, 12:39 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 11 Mar 2011, 11:44 AM
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!
0
Patrick
Top achievements
Rank 1
answered on 12 Mar 2011, 06:43 PM
Thanks. This I also like using Telerik. Good controls and good and quick answers.

Thx
Tags
TreeList
Asked by
Patrick
Top achievements
Rank 1
Answers by
Veli
Telerik team
Patrick
Top achievements
Rank 1
Share this question
or