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

Hide footer of groups with one item

Description

Sometimes one might want to hide the group footer when the associated group has only one item.

"Example figure with removed single group footer"

Solution

In the ItemDataBound event handler, check for how many child items are there in a certain group. If there is only one child item, add the hidden CSS class.

Example

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridGroupFooterItem)
    {
        GridGroupFooterItem groupFooterItem = (GridGroupFooterItem)e.Item;  // Get a reference to the footer item
        GridGroupHeaderItem groupHeaderItem = groupFooterItem.GroupHeaderItem; // Get a reference to the header item
        GridItem[] groupItems = groupHeaderItem.GetChildItems(); // Get the children elements of each grouped items

        if (groupItems.Count() < 2)
            groupFooterItem.CssClass = "hidden";
    }
}
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)
    If TypeOf e.Item Is GridGroupFooterItem Then
        Dim groupFooterItem As GridGroupFooterItem = CType(e.Item, GridGroupFooterItem)
        Dim groupHeaderItem As GridGroupHeaderItem = groupFooterItem.GroupHeaderItem
        Dim groupItems As GridItem() = groupHeaderItem.GetChildItems()

        If groupItems.Count() < 2 Then groupFooterItem.CssClass = "hidden"
    End If
End Sub
<style>
    .RadGrid .rgMasterTable .rgFooter.hidden {
        display: none;
    }
</style>
In this article