简体   繁体   中英

Retrieve data from LinqDataSource before Skip and Take happen?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM