Reputation: 457
i just want to sum a column and show in footer but problem is that column sum is depend on other column value. Example in my grid i have two column one for price and second for currency code
Price CurrencyCode
100 Eur
54 GBP
65 GBP
89 USD
41 EUR
i wanted to sum a price according to currency code show sum in footer Like this Eur: 141 GBP: 119 USD: 89 how to do this help me.. thanks In Advance
Upvotes: 1
Views: 1232
Reputation: 457
var sumEur = yourtable.compute("sum(Price)",CurrencyCode='GBP');
var sumGBP = yourtable.compute("sum(Price)",CurrencyCode='EUR');
var sumUSD = yourtable.compute("sum(Price)",CurrencyCode='USD');
Upvotes: 1
Reputation: 911
You'll have to generate this text in your code behind. You can use the DataBound event of the grid if you want access to the data, although I would probably calculate this from the datasource directly. Using linq you can easily get sums like:
var sumEur = datasource.Where(i => i.CurrencyCode == "EUR").Sum(i => i.Price);
var sumUsd = datasource.Where(i => i.CurrencyCode == "USD").Sum(i => i.Price);
etc.
and then:
string total = String.Format("Eur: {0} GBP: {1} USD {2}", sumEur, sumGbp, sumUsd);
And then just place the total string in your page how and where you want it.
Upvotes: 0