ASP.NET MVC 3 WebGrid分页问题

时间:2021-07-19 04:13:00

My data access layer returns collection with rows for single page and total number of rows.

我的数据访问层返回带有单页行数和总行数的集合。

Unfortunately WebGrid component does not allow to specify total number of rows or total number of pages (these properties are read-only).

遗憾的是,WebGrid组件不允许指定总行数或总页数(这些属性是只读的)。

Has anyone had to deal with this issue before?

以前有人不得不处理这个问题吗?

3 个解决方案

#1


21  

You can use the Bind method on the WebGrid to tell the grid to use server side paging.

您可以使用WebGrid上的Bind方法告诉网格使用服务器端分页。

grdv.Bind(myData, rowCount=10000, autoSortAndPage=False)

grdv.Bind(myData,rowCount = 10000,autoSortAndPage = False)

Setting autoSortAndPage to false tells the grid that myData is just a segment of the data. It will show all rows of this data regardless of your page size setting. Pager will be built using the rowCount you pass in and not the number of records in myData.

将autoSortAndPage设置为false会告诉网格myData只是数据的一部分。无论您的页面大小设置如何,它都会显示此数据的所有行。将使用您传入的rowCount而不是myData中的记录数来构建寻呼机。

#2


6  

EDIT: I see what your question is now. Check out this article for not using the WebGrid.

编辑:我现在看到你的问题。看看这篇文章没有使用WebGrid。

Paging with WebGrid

From this page, it looks like you can specify rows per page.

在此页面中,您似乎可以指定每页的行数。

var grid = new WebGrid(source, rowsPerPage : 25);

And this page (look at line 9 from the first code block).

这个页面(从第一个代码块看第9行)。

#3


2  

rowsPerPage is only settable through the constructor. This was done to keep the helper simple and avoid handling complex states. Total rows comes from the data source.

rowsPerPage只能通过构造函数进行设置。这样做是为了使助手简单并避免处理复杂状态。总行数来自数据源。

#1


21  

You can use the Bind method on the WebGrid to tell the grid to use server side paging.

您可以使用WebGrid上的Bind方法告诉网格使用服务器端分页。

grdv.Bind(myData, rowCount=10000, autoSortAndPage=False)

grdv.Bind(myData,rowCount = 10000,autoSortAndPage = False)

Setting autoSortAndPage to false tells the grid that myData is just a segment of the data. It will show all rows of this data regardless of your page size setting. Pager will be built using the rowCount you pass in and not the number of records in myData.

将autoSortAndPage设置为false会告诉网格myData只是数据的一部分。无论您的页面大小设置如何,它都会显示此数据的所有行。将使用您传入的rowCount而不是myData中的记录数来构建寻呼机。

#2


6  

EDIT: I see what your question is now. Check out this article for not using the WebGrid.

编辑:我现在看到你的问题。看看这篇文章没有使用WebGrid。

Paging with WebGrid

From this page, it looks like you can specify rows per page.

在此页面中,您似乎可以指定每页的行数。

var grid = new WebGrid(source, rowsPerPage : 25);

And this page (look at line 9 from the first code block).

这个页面(从第一个代码块看第9行)。

#3


2  

rowsPerPage is only settable through the constructor. This was done to keep the helper simple and avoid handling complex states. Total rows comes from the data source.

rowsPerPage只能通过构造函数进行设置。这样做是为了使助手简单并避免处理复杂状态。总行数来自数据源。