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

Rendered Tree Items

1 Answer 61 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 15 Feb 2011, 01:18 AM
Hi.

I'd like to know how to get from the radtreelist, the dataitems that will be rendered after requesting a node expansion, and in which event it could be done.

I've tried the following code, but without success.

protected void TreeList_Load(object sender, EventArgs e)
{
     MyTreeList.DataSource = ws.GetSales(); 
     //This retrieves an array of objects which represent the sales of several stores,
     //their managers and their employees
  
     TreeListDataItemCollection rendered_items = MyTreeList.Items;
  
     object[] data = rendered_items.Select(s => s.DataItem).ToArray(); 
     //I thought this would get the DataBoundItems
     //in the treelist, but instead it gets an Array with null objects
  
     //Code for Exporting the desired data
}

By the way, getting the Items from "MyTreeList" in the OnLoad event, retrieves me the Items shown in the previous state of the control, not the ones that were recently asked for, so I don't know which event could work better. Could you help me?

Regards

1 Answer, 1 is accepted

Sort by
0
Accepted
Tsvetina
Telerik team
answered on 18 Feb 2011, 08:56 AM
Hello Ivan,

You can retrieve the new items in RadTreeList after it is expanded or collapsed in its DataBound event. In order to perform this action only after expand or collapse has happened, you can wire the ItemCommand event and raise a flag if the command name is ExpandCollapse. Here is a portion of sample code demonstrating this approach:
bool isExpandedOrCollapsed = false;
protected void RadTreeList1_ItemCommand(object sender, TreeListCommandEventArgs e)
{
    if (e.CommandName == RadTreeList.ExpandCollapseCommandName)
    {
        isExpandedOrCollapsed = true;
    }
}
protected void RadTreeList1_DataBound(object sender, EventArgs e)
{
    if (isExpandedOrCollapsed)
    {
        List<TreeListDataItem> items = new List<TreeListDataItem>();
        foreach (TreeListDataItem item in RadTreeList1.Items)
        {
            items.Add(item);
        }
    }
    isExpandedOrCollapsed = false;
}

As for the Load event of the control, same as with the other RadControls, it is fired before the postback changes have happened. You can see the lifecycle of RadControls in this help article.

Best wishes,
Tsvetina
the Telerik team
Tags
TreeList
Asked by
Ivan
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or