简体   繁体   English

使用Linq在Gridview中分页

[英]Paging in Gridview with Linq

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. 我知道我的其他各种问题的类型已在SO中列出,但我认为我的问题与现有问题完全不同,或者我的方法有所不同。

I have a table call tblListing where there is 108 columns, in which i have 170000 records and increasing. 我有一个表调用tblListing,其中有108列,其中我有170000条记录并在增加。 In my admin section i am pulling out 20 columns. 在我的管理部分,我要拔出20列。 But the problem is the its taking more than a minute to display in gridview. 但问题是它需要花费一分多钟才能在gridview中显示。

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. 现在我应用LINQ,并使用.Take(20),但它只显示20条记录。

So I want to load 20 records at a time, while paging. 因此,我想在分页时一次加载20条记录。

Please help. 请帮忙。 Any sample code or refence will be highly appreciated. 任何示例代码或参考将不胜感激。

Looks like this article about Paging With LINQ may be helpful for you: 这篇关于使用LINQ进行分页的文章可能对您有所帮助:

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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