I would suggest to use LINQ Query to assign datasource to the grid as mentioned below :
For Example My class name is stock then
STOCK Class:
public class Stock
{
public int Id { get; set; }
public int Quantity { get; set; }
public int Bonus { get; set; }
public int Price { get; set; }
public int Total { get; set; }
}
Then below linq query should be used to assign datasource :
var stocks = stockList.Select(s => s.Id).Distinct().Select(stock => new Stock
{
Id = stock,
Quantity = stockList.Where(s => s.Id == stock).Sum(s => s.Quantity),
Bonus = stockList.Where(s => s.Id == stock).Sum(s => s.Bonus),
Price = stockList.Where(s => s.Id == stock).Select(s => s.Price).FirstOrDefault(),
Total = stockList.Where(s => s.Id == stock).Sum(s => s.Total),
}).ToList();
Note : Above query will sum all the properties except ID and price. and stockList is the list object of Stock which contains all the data for Stock.