New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Have different text in the GroupFooters and the GridFooter

DESCRIPTION

How do I show different descriptions for the Group Footer and Grid Footer in the RadGrid? When I set a FooterAggregateFormatString on a column, the same FormatString is used for both the Group Footer and Grid Footer.

SOLUTION

The RadGrid uses a single format string for both the GridFooterItem and GridGroupFooterItem, so the same string will be used in both footers. In some situations it may be desirable to have different strings for those sections, such as a Subtotal and Grand Total configuration.

The ItemDataBound event event can be used to override the text in the RadGrid column footer. The first step is to define the FooterAggregateFormatString so that it only contains the aggregate value, see below.

<telerik:GridBoundColumn DataField="SampleColumn" Aggregate="Sum" FooterAggregateFormatString="{0}" />

In the ItemDataBound event, you can distinguish whether the Bound item is a GridFooterItem or GridGroupFooterItem and modify the Cell Text accordingly.

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFooterItem)
    {
        var valueFooterCell = (e.Item as GridFooterItem)["SampleColumn"];
        valueFooterCell.Text = "Grand Total: " + valueFooterCell.Text;
    }
    else if (e.Item is GridGroupFooterItem)
    {
        var valueFooterCell = (e.Item as GridGroupFooterItem)["SampleColumn"];
        valueFooterCell.Text = "Subtotal: " + valueFooterCell.Text;
    }
}
In this article
Not finding the help you need? Improve this article