Santosh Kumar

Santosh Kumar

  • NA
  • 126
  • 60.3k

How to perform sum of all cells using linq and bind to grid

May 14 2013 5:47 AM
Hi,
  

I have a requirement. like....
Sname Marks Percentage
aa       50        50
aa       60        60
bb      80        80
bb      60        60

here i want to add marks and display percentage like below dynamically

Sname Marks Percentage
aa         50      50
aa         60      60
aa        110     55
bb        80      80
bb        60     60
bb       140    70

It should be done using the linq query I am using the follwing linq query which performs grouping for display.

List<Studentsmarkslist > mrksbrpby = (from n in lstmrks group n by new { n.StudentName,n.Total,n.Percentage } into g
                                                            orderby g.Key.StudentName
                                                            select new Studentsmarkslist { StudentName = g.Key.StudentName,
                                                            Total = g.Key.Total,
                                                            Percentage = g.Key.Percentage
                                                             }).ToList();

        return mrksbrpby

Answers (2)