I have a GridView that uses LinqDataSource. The GridView has default paging enable. I would like to retrieve the data from LinqD开发者_StackOverflow中文版ataSource 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.
加载中,请稍侯......
精彩评论