ASP.NET 4.5 GridView.AllowCustomPaging属性如何使这更简单?

Ces*_*iel 3 asp.net paging gridview .net-4.5

我有一个ASP.NET 4 GridView控件,它使用这两篇​​文章中讨论的逻辑:

ASP.NET 4.5 GridView.AllowCustomPaging属性如何使这更简单?

关于如何使用它的文章的链接将非常受欢迎.

Mer*_*nzo 5

在我最近的经历中,它没有.

具体来说:在使用ASP.NET 4.5的模型绑定系统时,实现高效的GridView自定义分页(仅从非常大的数据库表中检索所需的数据页)时,该GridView.AllowCustomPaging属性未进入该属性.

设置GridView.SelectMethod属性会导致使用Model Binding,它为我们提供了"ObjectDataSource-style"功能(如链接中所述),而不需要ObjectDataSource.在这种方法中,有两种选择:

(1)GridView.SelectMethod返回a 指定的方法IQueryable,例如:

public IQueryable<MyClass> MySelectMethod1()
{
    return myService.GetAll(someCriteria);
}
Run Code Online (Sandbox Code Playgroud)

如果您不介意将IQueryable暴露给Presentation Tier,那么这是实现非常高效的分页的一种非常快速的方法.在运行时,框架会根据GridView 和属性自动将Skip()和Take()方法应用于源.仅从数据库返回所需的结果页面.简单!PageIndexPageSize

(2)指定的方法GridView.SelectMethod返回一些其他可绑定对象,例如:

public IList<MyClass> MySelectMethod2(int startRowIndex, int maximumRows, out int totalRowCount)
{
    totalRowCount = myService.GetCount(someCriteria);
    return myService.GetPage(someCriteria, startRowIndex, maximumRows);
}
Run Code Online (Sandbox Code Playgroud)

通过设置totalRowCount,我们现在已经为GridView提供了正确呈现其寻呼机所需的所有信息,同时只从数据库中检索了所需的数据页面.

我早就预料到使用VirtualItemCount属性(如描述在这里),但据我所知道的,totalRowCount从参数避免了VirtualItemCount财产.

如果未实现(1)(2),则GridView将抛出异常:
当DataBoundControl启用了分页时,SelectMethod应该返回IQueryable或者应该具有所有这些必需参数:int startRowIndex,int maximumRows,out int totalRowCount

所以,我们在ASP.NET 4.5中实现的GridView自定义分页....但GridView.AllowCustomPagingGridView.VirtualItemCount不见踪影!