views:

330

answers:

1

I'm using a LinqDataSource to populate a basic GridView in ASP.NET. The user has the ability to filter the results, so I use a few WhereParameters and the Where within the LinqDataSource.

My client has requested an option to export the filtered results to a file. Easy enough to pipe the data into a file, but I would prefer not to rewrite all the where clauses in the codebehind. I would simply like to extract the full set of results, preferably by using the already configure LinqDataSource.

When using LinqDataSource's OnSelect method, the e.Result has the data I'm after, but my GridView PageSize is set to 20, which means that the LinqDataSource (rightly so) only fetches the first 20 records.

Is there anyway to get hold of the entire data set?

A: 

Ok, found the solution courtesy of AspGuy, Aref Karimi.

The following will retrieve all records by using the LinqDataSource's configuration. Sweet as!

    IDataSource source = (IDataSource)myLinqDataSource;
    LinqDataSourceView view = source.GetView("DefaultView") as LinqDataSourceView;

    DataSourceSelectArguments args = new DataSourceSelectArguments();
    args.RetrieveTotalRowCount = view.CanRetrieveTotalRowCount;
    args.SortExpression = view.OrderBy;

    List<MyObject> objects = view.Select(args) as List<MyObjects>;
Andy