4 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Jul 2009, 07:13 AM
Hello,
Check out the folowing code snippet which shows how to set the aggregate function for a column and FooterFormatString for the grid:
c#:
Thanks
Princy.
Check out the folowing code snippet which shows how to set the aggregate function for a column and FooterFormatString for the grid:
c#:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) |
| { |
| if (col.UniqueName == "column") |
| { |
| (col as GridBoundColumn).Aggregate = GridAggregateFunction.Count; |
| (col as GridBoundColumn).FooterAggregateFormatString = "{0:C2}"; |
| } |
| } |
| } |
Thanks
Princy.
0
andieje
Top achievements
Rank 1
answered on 14 Jul 2009, 03:09 PM
thanks
0
Chris
Top achievements
Rank 1
answered on 17 Feb 2011, 08:42 PM
I am trying to do the exact same thing. My grid is bound to a SQL Datasource. I do not know all of the columns in the dataset (the user defines what data is in their dataset), however, I want to implement something like the following:
If the grid contains the column "PRODUCT_UNITS", I want to add an aggregate to it automatically like above. When I implement the code above, .NET errors and says "Cannot find column [PRODUCT_UNITS]". I know for a fact this column is in the dataset and is bound in the grid (grid has AutoGenerateColumns=True). If I do a response.write of the col.UniqueName in the For loop, it prints PRODUCT_UNITS. If I comment out all of the code above, the grid draws properly (no aggregating) and one of the columns is PRODUCT_UNITS.
What am I doing wrong?
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBoundFor Each col As GridColumn In RadGrid1.MasterTableView.RenderColumnsIf col.UniqueName = "PRODUCT_UNITS" ThenTryCast(col, GridBoundColumn).Aggregate = GridAggregateFunction.AvgTryCast(col, GridBoundColumn).FooterAggregateFormatString = "<strong>{0} (Avg)</strong>"End IfNextnd SubIf the grid contains the column "PRODUCT_UNITS", I want to add an aggregate to it automatically like above. When I implement the code above, .NET errors and says "Cannot find column [PRODUCT_UNITS]". I know for a fact this column is in the dataset and is bound in the grid (grid has AutoGenerateColumns=True). If I do a response.write of the col.UniqueName in the For loop, it prints PRODUCT_UNITS. If I comment out all of the code above, the grid draws properly (no aggregating) and one of the columns is PRODUCT_UNITS.
What am I doing wrong?
0
Chris
Top achievements
Rank 1
answered on 18 Feb 2011, 03:43 AM
I figured out my issue. This post lead me to my answer: http://www.telerik.com/community/forums/aspnet-ajax/grid/dynamic-columns-in-a-grid-and-grouping-aggregate-problem.aspx
I had to set UseAllDataFields="True" of the MasterTableView. Also, instead of setting the aggregate function in ItemDataBound, I put it on ColumnCreated. Not sure if one is better than the other, but for what I'm doing that is working for me.
Thanks,
Chris
I had to set UseAllDataFields="True" of the MasterTableView. Also, instead of setting the aggregate function in ItemDataBound, I put it on ColumnCreated. Not sure if one is better than the other, but for what I'm doing that is working for me.
Thanks,
Chris