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

How do you format Groupfooter?

5 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 30 Apr 2008, 11:32 PM
Adding the groupfooter and calculating a total for a column was pretty easy, but how can I format the output so that it shows something besides "Sum: 9999"?

5 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 01 May 2008, 08:47 AM
Hi Steve,

You can alter the text, as shown in the code sample below:

.cs
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridGroupFooterItem)  
        {  
            GridGroupFooterItem groupFooter = (GridGroupFooterItem)e.Item;  
            groupFooter.Cells[4].Text = "Custom TEXT for agregate count: ";  
        }  
    } 

I hope this helps.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Steve
Top achievements
Rank 1
answered on 01 May 2008, 03:59 PM
Cool.  Thanks!
0
Gino Suarez
Top achievements
Rank 1
answered on 15 Dec 2009, 05:30 PM
Hi, this is really cool, but how can i know the groupheadertext or name to put it on its own groupfooter , something like this

GroupHeadetext:  "SuperTelerik"
                                                some data1
                                                some data 2
              footertext:   "SubTotal of SuperTelerik"

Best Regards

Gino
0
Princy
Top achievements
Rank 2
answered on 16 Dec 2009, 06:52 AM
Hello Gino,

Try out the following code and see if it helps achieve your scenario:
c#:
string headertext;
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem groupheaderItem = (GridGroupHeaderItem)e.Item; 
            headertext = groupheaderItem.DataCell.Text.Substring(groupheaderItem.DataCell.Text.IndexOf(':') + 1); 
        } 
 
        if (e.Item is GridGroupFooterItem) 
        { 
            GridGroupFooterItem groupFooterItem = (GridGroupFooterItem)e.Item; 
            string strtxt = groupFooterItem["ColumnUniqueName"].Text.Substring(groupFooterItem["ColumnUniqueName"].Text.IndexOf(':') + 1); 
            if (headertext != null
              groupFooterItem["ColumnUniqueName"].Text = "SubTotal of " + headertext + ":" + strtxt; 
        } 

Thanks
Princy.
0
Shawn Clabough
Top achievements
Rank 1
answered on 20 Dec 2011, 08:38 PM
I used this recently, but found one issue with it.  I thought I'd share my solution.

The issue is that this only works properly with one group level.  If there is more than one group level, the footers for the parent groups get the label from the last child.  To solve this, I changed to this.

Private _headerText As New List(Of String)
 
Private Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
    If TypeOf e.Item Is GridGroupHeaderItem Then
        Dim groupheaderItem As GridGroupHeaderItem = DirectCast(e.Item, GridGroupHeaderItem)
        _headerText.Add(groupHeaderItem.DataCell.Text.Substring(groupHeaderItem.DataCell.Text.IndexOf(":") + 1))
    End If
 
    If TypeOf e.Item Is GridGroupFooterItem Then
        Dim groupFooterItem As GridGroupFooterItem = DirectCast(e.Item, GridGroupFooterItem)
        Dim txt As String = groupFooterItem("ColumnUniqueName").Text.Substring(groupFooterItem("ColumnUniqueName").Text.IndexOf(":"c) + 1)
        If _headerText IsNot Nothing Then
            groupFooterItem("ColumnUniqueName").Text = _headerText.Item(_headerText.Count - 1) & " Subtotal: " & txt.Trim()
            _headerText.RemoveAt(_headerText.Count - 1)
        End If
    End If
End Sub
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Steve
Top achievements
Rank 1
Gino Suarez
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Shawn Clabough
Top achievements
Rank 1
Share this question
or