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

Customize Aggregate Column in Group Footer Totals Row

3 Answers 225 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 20 Jan 2009, 12:46 AM
Hello,

I'm having trouble with this.
I have a grid that is grouped by date.

I have a column with aggregate marked as sum. This column holds a number in seconds, which I convert to minutes for display during the ItemDataBound Event.

Now in the footer it will sum the values and display as seconds, but I need to show it in minutes. I tried to get at this value in the ItemDataBound event but it seems to grab the value of the final row before the sum calculation on the grouping is performed.

 

if (e.Item is GridGroupFooterItem)

 

{

 

GridGroupFooterItem item = (GridGroupFooterItem)e.Item;

 

 

DataRowView groupDataRow = (DataRowView)e.Item.DataItem;

 

 

 

foreach (DataColumn column in groupDataRow.DataView.Table.Columns)

 

 

//Check the condition and add only the field you need

 

 

if (column.ColumnName == "Stop Idle")

 

{

 

double si = double.Parse(groupDataRow["Stop Idle"].ToString());

 

item.Cells[column.Ordinal].Text = (si / 60).ToString();

}

}

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Jan 2009, 07:45 AM
Hi Mark,

I hope you have set the Aggregate property of the desired column to Sum. If so you can access the GroupFooterItem and footertext (sum) in the ItemDataBound event and convert the value to minutes.

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridGroupFooterItem) 
        { 
            GridGroupFooterItem item = (GridGroupFooterItem)e.Item; 
           // Access the sum from the Footer 
           string strtxt = ((Telerik.Web.UI.GridTableCell)(item.Controls[4])).Text.Split(':')[1]; 
            double si = double.Parse(strtxt ); 
             
            // convert the value to minutes 
            ((Telerik.Web.UI.GridTableCell)(item.Controls[4])).Text ="Sum :" + (si / 60).ToString(); 
        
        } 
 
    } 


Thanks
Shinu
0
Matt
Top achievements
Rank 1
answered on 20 Jan 2009, 03:09 PM
Thanks for the help Shinu, but I get errors.

((Telerik.Web.UI.GridTableCell)(item.Controls[4])).Text
is equal to  

What is significant about control 4? I tried changing that number while debugging and they all brought back  
There was a count of 24 Controls



0
Shinu
Top achievements
Rank 2
answered on 21 Jan 2009, 04:11 AM
Hi Matt,

Are you showing Aggregate in each GroupFooter?  I have set the Aggregate property of the Grid column to Sum and enabled ShowGroupFooter property on my end.  In my case ((Telerik.Web.UI.GridTableCell)(item.Controls[4])).Text  contained the aggregate value in the GroupFooter. Can you send your entire aspx?

Shinu
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Matt
Top achievements
Rank 1
Share this question
or