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

How to put "Count" into the header in grouping?

1 Answer 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ervin
Top achievements
Rank 1
ervin asked on 29 Sep 2011, 01:00 AM
Hi,

I would like to have a "Count" in the group header and "Sum" in the footer PROGRAMMATICALLY. I managed to see the "Sum" in the footer using the Aggregate function but still the footertext is missing. And also "Count" in "Group Header" is missing...  

I already checked the examples but could not find an appropriate answer for that. I think no one used them together programmatically!

What I need is something like;

VendorName (4)        Total
--------------                -------
ModelName1               25
ModelName2               25
ModelName3               25
ModelName4                 5
My Sum:                      80

Footertext "My Sum" and Count "(4)" are missing in my code!!!

Thanks for your help in advance,
Ervin

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Sep 2011, 10:54 AM
Hi ervin,

You can follow this approach to add count into the header in grouping.

C#:
int total;
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
    {
            GridDataItem dataItem = e.Item as GridDataItem;
            GridGroupByExpression exp = new GridGroupByExpression();
            GridGroupByField expfield = new GridGroupByField();
            expfield = new GridGroupByField();
            expfield.FieldName = "OrderID";
            expfield.HeaderText = "Order count ";
            expfield.Aggregate = GridAggregateFunction.Count;
            expfield.FormatString = "({0})";
            exp.SelectFields.Add(expfield);
            expfield = new GridGroupByField();
            expfield.FieldName = "UnitPrice";
            exp.GroupByFields.Add(expfield);
            this.RadGrid1.MasterTableView.GroupByExpressions.Add(exp);
            int fieldValue = int.Parse(dataItem["OrderID"].Text);
            total += fieldValue;
   }
   if (e.Item is GridGroupFooterItem)
    {
            GridGroupFooterItem itm = e.Item as GridGroupFooterItem;
            itm["OrderID"].Text = "Total :" + total.ToString();
            total = 0;
    }
}

Thanks,
Princy.
Tags
Grid
Asked by
ervin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or