Style TreeListFooterItem with Parent node Properties

6 posts, 1 answers
  1. Derek
    Derek avatar
    19 posts
    Member since:
    Jun 2011

    Posted 13 Dec 2011 Link to this post

    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?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Dec 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Derek
    Derek avatar
    19 posts
    Member since:
    Jun 2011

    Posted 15 Dec 2011 Link to this post

    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.
  5. Derek
    Derek avatar
    19 posts
    Member since:
    Jun 2011

    Posted 16 Dec 2011 Link to this post

    Anything?
  6. Answer
    Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 19 Dec 2011 Link to this post

    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
  7. Derek
    Derek avatar
    19 posts
    Member since:
    Jun 2011

    Posted 19 Dec 2011 Link to this post

    That worked perfectly. Thanks for the help.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017