在分页GridView的使用LINQ [英] Paging in Gridview with Linq
问题描述
我知道我的类型的其他各种问题这里列出的SO,但我想我的问题是从现有的一矿的做法完全不同有所不同。
I know my types of various other issues are listed here in SO, but I think my issue is quite different from the existing one or mine approach is different.
我有一个表调用tblListing那里有108列,其中我有17万的记录和增加。在我的管理部分我正在拉出20列。但问题是其采取不到一分钟的GridView控件来显示更多。
I have a table call tblListing where there is 108 columns, in which i have 170000 records and increasing. In my admin section i am pulling out 20 columns. But the problem is the its taking more than a minute to display in gridview.
早些时候,我使用的数据表显示的记录,但页面和系统变得非常缓慢。现在我申请LINQ,并使用。取(20),但其只显示20条记录。
Earlier , i was using datatable to display the records, but the page and system became very sluggish. Now i applied LINQ, and is using .Take(20),but its displaying only 20 records.
所以我要加载20条记录的时间,而分页。
So I want to load 20 records at a time, while paging.
请帮忙。任何样品code或refence将是非常美联社preciated。
Please help. Any sample code or refence will be highly appreciated.
推荐答案
看起来像这篇文章的分页使用LINQ 可能对你有所帮助:
Looks like this article about Paging With LINQ may be helpful for you:
下面是有关的code:
Here's the relevant code:
public static class PagingExtensions
{
//used by LINQ to SQL
public static IQueryable<TSource> Page<TSource>(this IQueryable<TSource> source, int page, int pageSize)
{
return source.Skip((page - 1) * pageSize).Take(pageSize);
}
//used by LINQ
public static IEnumerable<TSource> Page<TSource>(this IEnumerable<TSource> source, int page, int pageSize)
{
return source.Skip((page - 1) * pageSize).Take(pageSize);
}
}
这篇关于在分页GridView的使用LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!