views:

24

answers:

1

Hello,

I have a GridView that uses LinqDataSource. The GridView has default paging enable. I would like to retrieve the data from LinqDataSource before the paging takes place so that I could calculate the Sum of one single column of the whole database using Linq2SQL.

Right now, I'm using LinqDataSource_Selected event with LinqDataSourceStatusEventArgs.Result, but it only returns me the data AFTER paging (that is, the data on that page).

protected void linqDataSource_Selected(Object sender, LinqDataSourceStatusEventArgs e)  
{  
    var totalTime = (e.Result as List<Ticket>).Sum(t => t.TimeSpent);  
    gridView.Columns[8].FooterText = "Sum: " + totalTime;  
}

So my question is: How can I retrieve data from LinqDataSource before paging takes place?

+1  A: 

The LINQDataSource class has a GetView() method which returns a DataSourceView object. DataSourceView has an ExecuteSelect() method which will query the datasource directly. You should be able to use LINQ syntax on the ExecuteSelect() method to get your sum.

Dave Swersky
Hi, thanks for replying! Would you mind explaining more? I tried to call GetView() from my LINQDataSource (`linqDataSource.GetView()`), but Visual Studio gives me this error: `cannot access method 'GetView' here due to its protection level`
Son Tran-Nguyen
You're right, that GetView() method is protected. I can't seem to find anything about querying directly using a LINQDataSource. You might be better off creating a separate LINQDataSource just for the sum.
Dave Swersky