简体   繁体   English

GridView AllowPaging = true,但是实现了我自己的分页,但是使用了asp.net分页器

[英]GridView AllowPaging = true but implement my own paging but use the asp.net pager

ASP.net webforms here, if I set AllowPaging=true and implement my own paging mechanism where I am fetching say 25 records at a time. 如果我设置AllowPaging = true并实现我自己的分页机制,则一次获取25条记录,则是ASP.net Webforms。 I'd like to be able to use the default gridview pager, but it seems to be having trouble setting the number of pages. 我希望能够使用默认的gridview分页器,但是似乎在设置页面数时遇到了麻烦。 Is this an internal calculation where the ENTIRE dataset has to be binded for it to determine this calculation? 这是内部计算,必须绑定ENTIRE数据集才能确定此计算?

For instance, assume a query has 1000 rows and I want to only fetch 25 of them at a time. 例如,假设一个查询有1000行,而我一次只想获取25行。 Does the gridview pager need to execute the 1000 rows as its datasource in order to get the correct number of pages (buttons) to display. gridview传呼机是否需要执行1000行作为其数据源,以便获得要显示的正确页面数(按钮)。 I cant find a property allowing me to specify the number of pages, they all seem to be read only (get methods). 我找不到允许我指定页面数的属性,它们似乎都是只读的(get方法)。

I want to avoid building my own pager... 我想避免建立自己的传呼机...

The Effective Paging with GridView Control in ASP.NET Article describes how to implement the pagination where your gridview requests the data only for the page that is visible. ASP.NET中的使用GridView控件进行有效分页文章介绍了如何在您的gridview仅请求可见页面的数据的情况下实现分页。

Don't be put off by the fact that the database query is executed twice. 不要因为数据库查询执行了两次而被推迟。 Once for the total count and another to get the page's data. 一次用于总计数,另一次用于获取页面数据。 For applications with high traffic or a lot of data, this approach is still more efficient than getting everything, loading into a gridview (and the view state!), sending it to the end user, and the browser loading it on the screen :). 对于具有高流量或大量数据的应用程序,此方法比获取所有内容,将其加载到gridview(以及视图状态!),将其发送给最终用户以及将浏览器将其加载到屏幕上更加有效:) 。

That's where virtual paging comes in. 这就是虚拟分页进入的地方。

Set AllowCustomPaging to true . AllowCustomPaging设置为true

In PageIndexChanging event, set VirtualItemCount and PageIndex to the proper value. PageIndexChanging事件中,将VirtualItemCountPageIndex设置为适当的值。

Put only the 25 rows in the DataSource , do a DataBind as usual, you're done. 仅将25行放入DataSource ,照常执行DataBind ,即可完成。

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

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