This is a migrated thread and some comments may be shown as answers.

[Solved] LINQ To DataSet for RadGrid DataSource

0 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark Galbreath
Top achievements
Rank 2
Mark Galbreath asked on 24 Feb 2010, 02:37 PM
I just got into LINQ and read the chapters on it in Pro C# 2008 and the .NET 3.5 Platform and Pro ASP.NET 3.5 in C# 2008 (both from Apress).  I have run into an obstacle that I hope is not insurmountable: can I use a data projection when building a DataTable from a DataSet to be used as a datasource for a RadGrid?  Andrew Troelsen (Pro C# 2008) states that I cannot, but I have found no corroboration through Google.

For example, given I have an in-memory DataSet, ds, returned from Oracle that I want to use as the primary datasource for all RadGrids in my application (in other words, each RadGrid will take a subset of data from ds).  How do I make the following work?

1    var results = from t in ds.Tables[ 0 ].AsEnumerable()  
2  
3        group t by t.Field<string>( "MDEP" ), t.field<string>( "MDEP_DESC" ) into g  
4             
5        orderby g.Field<string>( "MDEP" )  
6             
7        select new {     
8           MDEP = g.Field<string>( "MDEP" ),  
9           MDEP_DESC = g.Field<string>( "MDEP_DESC" ),  
10          OA = g.Field<string>( "OA" ),  
11          OA_DESC = g.Field<string>( "OA_DESC" ),  
12          FY06 = g.Field<Int32>( "FY06" ),  
13          FY07 = g.Field<Int32>( "FY07" ),  
14          FY08 = g.Field<Int32>( "FY08" ),  
15          FY09 = g.Field<Int32>( "FY09" )  
16        };  
17  
18
19    DataTable dt = new DataTable();
20    dt = results.CopyToDataTable();
18    radGrid1.DataSource = dt

The compiler freaks out on line #3, claiming there is no "GroupBy" function for AsEnumerable(), which is more or less what Troelsen says will happen in his book.  The thing is, I HAVE to have these fields grouped.

I suspect that line #1 results in a list of datarows, which cannot be individually grouped, but I don't know LINQ well enough yet.

Any ideas?

tia,
Mark

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Mark Galbreath
Top achievements
Rank 2
Share this question
or