2
Answers

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

Santosh Kumar

Santosh Kumar

11y
1.7k
1
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)