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

Style TreeListFooterItem with Parent node Properties

5 Answers 88 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 13 Dec 2011, 05:10 PM
I need the ability to style each footer item with specific criteria from the parent node. The attached screen shot is partially what I need, but instead of having the root node be formatted on every total line, I need each aggregate to be formatted with that parent's name. Is this possible?

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Dec 2011, 05:43 AM
Hello,

Try the following code snippet.
CS:
protected void RadTreeList1_ItemDataBound(object sender, Telerik.Web.UI.TreeListItemDataBoundEventArgs e)
 {
   if (e.Item is TreeListFooterItem)
   {
        //your condition based on parent.
      TreeListFooterItem item = (TreeListFooterItem)e.Item;
      item.Style["background-color"] = "Red";
   }
 }

Thanks,
Princy.
0
Derek
Top achievements
Rank 1
answered on 15 Dec 2011, 03:44 PM
Princy, 

Thanks for you reply. In debug I see that I can get the values that I need, but because of the order in which the TreeList renders, I don't see a uniform way to format the data that I need. I need something that looks like this.

1
2
3
3a
3b
3c
3 - Team Total
4
1 - Team Total
Grand Total

Any guidance would be appreciated.
0
Derek
Top achievements
Rank 1
answered on 16 Dec 2011, 04:39 PM
Anything?
0
Accepted
Andrey
Telerik team
answered on 19 Dec 2011, 04:46 PM
Hello Derek,

Yes you could achieve your goal by hooking the ItemCommand events and ItemCreated events of RadTreeList.

In the ItemCommand's body you should check if the CommandName is "ExpandCollapse" and if it is to cast the e.Item object to TreeListDataItem, then to add one if statement that is checking whether the dataItem has parent item. And if the check is passed  to assign to the dataItem the parentItem. Namely:

protected void RadTreeList1_ItemCommand(object sender, TreeListCommandEventArgs e)
    {
        if (e.CommandName == "ExpandCollapse")
        {
            TreeListDataItem dataItem = e.Item as TreeListDataItem;
            if (dataItem.ParentItem != null)
            {
                dataItem = dataItem.ParentItem;
            }           
        }
    }

In the ItemCreated event handler you should check if the currently created item is TreeListFooterItem. If the result is true then cast the e.item to TreeListFooterItem, then check if the NestedLevel of the footerItem is different than -1. Namely:

protected void RadTreeList1_ItemCreated(object sender, Telerik.Web.UI.TreeListItemCreatedEventArgs e)
    {
        if (e.Item is TreeListFooterItem)
        {
            TreeListFooterItem footerItem = e.Item as TreeListFooterItem;
 
            if (footerItem.HierarchyIndex.NestedLevel != -1)
            {
                var dataItem = RadTreeList1.Items.Where(item => item.HierarchyIndex == footerItem.HierarchyIndex).First();
                footerItem["LocationID"].Text = "Parent node ID:  " + dataItem["LocationID"].Text;
            }
            else
            {
                footerItem["LocationID"].Text = "Global aggregate!";
            }          
        }       
    }

Best wishes,
Andrey
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
Derek
Top achievements
Rank 1
answered on 19 Dec 2011, 07:25 PM
That worked perfectly. Thanks for the help.
Tags
TreeList
Asked by
Derek
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Derek
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or