S VK

S VK

  • NA
  • 18
  • 0

linq to display data in matrix form

Nov 2 2017 1:15 AM
table as data as below
 
Id Std Div Count Cvalue
1 one A 50 Nos
2 one B 30 Nos
3 one C 40 Nos
4 one D 24 Nos
5 Two A 32 Nos
6 Two B 54 Nos
7 Two C 33 Nos
8 Two D 45 Nos
9 Three A 32 Nos
6 Three B 54 Nos
7 Three C 33 Nos
8 Three D 45 Nos
and so on ...
  1. DECLARE @Test AS TABLE(Id INT,Std CHAR(10),Div CHAR(10),[CountINT,Cvalue CHAR(10))  
  2. INSERT INTO @Test VALUES(1,'one','A',50,'Nos')  
  3. INSERT INTO @Test VALUES(2,'one','B',30,'Nos')  
  4. INSERT INTO @Test VALUES(3,'one','C',40,'Nos')  
  5. INSERT INTO @Test VALUES(4,'one','D',24,'Nos')  
  6. INSERT INTO @Test VALUES(5,'Two','A',32,'Nos')  
  7. INSERT INTO @Test VALUES(6,'Two','B',54,'Nos')  
  8. INSERT INTO @Test VALUES(7,'Two','C',33,'Nos')  
  9. INSERT INTO @Test VALUES(8,'Two','D',45,'Nos')  
  10. INSERT INTO @Test VALUES(9,'Three','A',32,'Nos')  
  11. INSERT INTO @Test VALUES(10,'Three','B',54,'Nos')  
  12. INSERT INTO @Test VALUES(11,'Three','C',33,'Nos')  
  13. INSERT INTO @Test VALUES(12,'Three','D',45,'Nos')  
I need to display data in view from database in matrix form as
 
 
 
i am not getting result with the below query
  1. var model = (from p in db.std  
  2. group p by p.Std into g  
  3. select new DataViewModel  
  4. {  
  5. rowKey = g.Key,  
  6. rowData = g.Select(s => new P1DataViewModel {Div= s.Div ,count= s.Count }).ToList()  
  7. }).ToList();  
  8. return View(model);

Answers (1)