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

Adding aggregates programmatically

3 Answers 148 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JD Plagianis
Top achievements
Rank 1
JD Plagianis asked on 04 Jun 2010, 02:00 AM

I have a page with one radgrid on it.  This page contains different sets of columns depending on how the user gets to the page.  In all cases the grid offers Grouping.  Since I cannot declare the columns ahead of time and I allow the user to group by whatever he/she chooses, how can i get specific columns to show aggregates in the group footers when grouping is active?

I can get footers to contain text by doing something simple like:

    Protected Sub Radgrid_ItemDataBound(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound  
        If TypeOf e.Item Is GridGroupFooterItem Then  
            Dim footer As GridGroupFooterItem = e.Item  
            Try  
                footer("ReworkCosts").Text = "Sum of Rework Costs: $" 
            Catch ex As Exception  
            End Try  
            Try  
                footer("MaterialCosts").Text = "Sum of Material Costs: $" 
            Catch ex As Exception  
            End Try  
            Try  
                footer("ScrapCosts").Text = "Sum of Scrap Costs: $" 
            Catch ex As Exception  
            End Try  
            Try  
                footer("DefectCosts").Text = "Sum of Defect Costs: $" 
            Catch ex As Exception  
            End Try  
            Try  
                footer("QNote").Text = "Count of Qnotes: " 
            Catch ex As Exception  
            End Try  
            Try  
                footer("MRCs").Text = "Count of MRCs: " 
            Catch ex As Exception  
            End Try  
            Try  
                footer("SCARs").Text = "Count of SCARs: " 
            Catch ex As Exception  
            End Try  
        End If  
    End Sub 

...but I don't know how to access all of the items in a specific column of that group so that I can add/count them and concatenate themm to the end of my string.

Any recommendations?

I am using VB.NET, .NET 3.5

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 04 Jun 2010, 07:07 AM
Hello JD Plagianis,

 
Try the following approach and see if it helps you.

VB.Net:
Protected Sub rgExtention_PreRender(sender As Object, e As EventArgs) 
    Dim i As Integer = 0 
    For Each groupHeader As GridGroupHeaderItem In rgExtention.MasterTableView.GetItems(GridItemType.GroupHeader) 
        Dim children As GridItem() = groupHeader.GetChildItems() 
        For Each child As GridDataItem In children 
            Dim childItem As GridDataItem = TryCast(child, GridDataItem) 
            Dim v As String = childItem("ReworkCosts").Text 
            total = total + Convert.ToInt16(v) 
        Next 
 
        Dim footer As GridGroupFooterItem = DirectCast(rgExtention.MasterTableView.GetItems(GridItemType.GroupFooter)(i), GridGroupFooterItem) 
        i += 1 
        footer.Cells(3).Text = "Sum of Rework Costs: $" + total.ToString() 
        total = 0 
    Next 
End Sub 

Regards,
Shinu.



0
JD Plagianis
Top achievements
Rank 1
answered on 04 Jun 2010, 05:10 PM
This is very helpful code, but the footer.Cells(3).Text part is confusing.  How do I change that 3 to be the same column number as the one I am aggregating?
0
Accepted
Shinu
Top achievements
Rank 2
answered on 05 Jun 2010, 06:13 AM
Hello,

You can access the footer for same column by using its ColumnUniqueName.

VB.Net:
footer("ReworkCosts").Text = "Sum of Rework Costs: $" + total.ToString()

Regards,
Shinu.


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