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

Data calculation with filtered data from gridview

1 Answer 33 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 08 Sep 2011, 07:50 PM
Hello ,

I have a gridview where I 'm using the filtered tools  in runtime.Now I would like to make some calculations (fe sum, averages) with this filtered data.
For example when I click on a seperate button, I should get the sum of a certain column of this filtered grid in a textblock. How should I deal with this ?
Kind regards,

Philip


1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 14 Sep 2011, 10:11 AM
Hi Philip,

RadGridView.Items contains the collection of items that represents the current view, i.e. the items left after filtering. Since you want to make external calculations over these items, you could use the handy Enumerable extension methods. 

For example, if your grid is bound to a collection of <Employee>, then you could sum their salaries like this:

var sumOfSalaries = this.radGridView.Items.Cast<Employee>().Sum(emp=>emp.Salary);

You can of course use any of the other extension methods and write more complex lambda's than the one I have here.

I hope this helps.

Best wishes,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Philip
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or