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 ......
Loading

Santhosh Kumar NallavelliPosted Aug 23, 2012, 4:42 AM
Here i am giving you detailed output .
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("TestData.xml"));
DataTable dt = ds.Tables[0];
TestData.xml sample structure(only one node as an example given)
var grps = from p in dt.AsEnumerable()
group p by p["org"].ToString() into g
select new
{
org= g.Key,
rows = (from q in g
select new
{
des = q["des"].ToString() ,
dept = q["Dept"].ToString(),
arr = q["Arr"].ToString(),
}).ToList()
};
gridview1.datasource = grps:
gridview1.databind();
Sample required output :
Hyderabad (This is origin)
Bangalore 15:40 21:15
Mumbai 14:20 16:35
Chennai (Another Origin)
Bangalore 12:20 13:20
Kolkatta 14:50 16:30
---
---
---
This output i need to get .
Sukesh MarlaPosted Aug 22, 2012, 12:44 PM
Santhosh Kumar NallavelliPosted Aug 22, 2012, 1:02 AM
I want to group based on origin and to display the corresponding destination,departure,arrival.
but when i use the above query it is showing in gridview only the origin values but not the remaining values .
i.e., the inner query results are not binding to gridview when i use the same query to export to excel sheet i got the result.
Sukesh MarlaPosted Aug 21, 2012, 6:13 AM