4
Answers

Binding Linq main Query and sub query results to gridview

Hi all ,

I have a Linq Query in the foloowing way .

var query= from p in dt.AsEnumerable()  group p by p["A"].ToString() into g select new
 {
  city = g.Key,
  sub_rows  = (from q in g
  select new
  {
  value1= q["B"].ToString() ,
  value2 = q["C"].ToString(),
  value3= q["D"].ToString(),
  }).ToList()
  };
here A,B,C,D are data columns in my datatable.

I want to assign the results to gridview. But when i tried it is assigning only main query results i.e, here the city(key value) but not the inner query results (sub_rows .) '
Please suggest me.

Desired Sample output :

group1 name (Key value)
Corresponding rows ......
group2 name
Corresponding rows ......

Answers (4)