First Level Group Totals

Thread is closed for posting
1 posts, 0 answers
  1. A9E74E7C-52FA-4440-8D67-C26A0770B01B
    A9E74E7C-52FA-4440-8D67-C26A0770B01B avatar
    16 posts
    Member since:
    May 2004

    Posted 22 Mar 2007 Link to this post

    Requirements

    r.a.d.controls version

    Q4 2006
    .NET version .NET 2.0
    Visual Studio version

    2005
    programming language

    C#
    browser support

    all browsers supported by r.a.d.controls


    Note: The group footers feature is available out of the box in RadGrid for ASP .NET AJAX. For more information please review this online example.
     
    PROJECT DESCRIPTION
    Getting an extra row (item) after a group and displaying a total value for the entire group is a common requirement that, unfortunately, is not yet natively supported by RadGrid. The good news is that we can emulate this for single-level grouping quite easily. Here is how:
    • We have to go over all groups and add an extra item after the last item that will contain the totals text. We are using the GridNoRecordsItem as it is one of the simple item types.
    • Adding an item will modify the grid's control tree and we need to do this after the SaveViewState lifecycle stage, so that we avoid ViewState corruption on postback.
    • Having the new item created after SaveViewState means it does not have ViewState available and controls placed inside must not use the ViewState.
    The attached project contains a class that inherits from RadGrid: GroupTotalsGrid. It contains two extra properties:
    • TotalsColumn: this is the column whose values we will get and sum up. We are using DataKeyValues, so that column must be added to  the DataKeyNames collection.
    • TotalsFormatString: used to supply additional formatting for your totals text display. The default is "Total: {0}".
    Our grid definition now looks like this:
    <telerik:GroupTotalsGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None" 
    ShowGroupPanel="True" TotalsColumn="ProductSales" TotalsFormatString="Total Sales: ${0}" Width="700px"
    ... 
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.