ASP.NET MVC 3 WebGrid paging issue
Asked Answered
L

3

14

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).

Has anyone had to deal with this issue before?

Lubeck answered 15/11, 2010 at 14:47 Comment(2)
What is WebGrid? Does MVC support it? Sounds like an ASP.net WebForms control.Prove
Webgrid is new in MVC 3 - weblogs.asp.net/shijuvarghese/archive/2010/10/08/…Fite
A
22

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

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.

Aluin answered 30/12, 2010 at 1:45 Comment(1)
My grid does not allow this member. Pager not showing. "rowsPerPage" is limiting my grid to this number of rows.Falchion
F
6

EDIT: I see what your question is now. Check out this article for not using the 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).

Fite answered 15/11, 2010 at 17:56 Comment(1)
Yes, but I have no way to specifiy total number of rows :(Lubeck
C
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.

Chappell answered 18/11, 2010 at 21:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.