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

[Solved] Sum column of filtered grid rows only

2 Answers 327 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Acadia
Top achievements
Rank 1
Iron
Acadia asked on 18 Jun 2009, 12:17 PM
How do I sum only the columns that are in the grid after it has been filtered?  I can only seem to get the sum of all of the values for the column before it was filtered.

After the filter has been performed and the datasource set and the grid rebound, I have the followjng code which loops through the grid and sums the column.  But it always shows the sum of all rows from the original datasource and not the filtered rows:

 

For Each item As GridDataItem In rgT.MasterTableView.Items

 

lblAmt =

CType(item.FindControl("lblTransAmount"), Label)

 

 

Try

 

transTotal += System.Convert.ToDouble(Replace(lblAmt.Text,

"$", ""))

 

 

Catch ex As Exception

 

lblUpdMsg.Text =

"There was an error summing the transactions. " & ex.Message

 

 

Exit For

 

 

End Try

 

 

Next

 


Any help would be appreciated!
Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 23 Jun 2009, 07:45 AM
Hi Acadia,

Try placing this code in RadGrid's PreRender event, where your grid should contain only the filtered items when you loop through them.

Kind regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Acadia
Top achievements
Rank 1
Iron
answered on 23 Jun 2009, 11:01 AM
That's perfect thanks!
Tags
Grid
Asked by
Acadia
Top achievements
Rank 1
Iron
Answers by
Veli
Telerik team
Acadia
Top achievements
Rank 1
Iron
Share this question
or