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?

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Daniil Harik
  • 4,619
  • 10
  • 55
  • 60
  • 1
    What is WebGrid? Does MVC support it? Sounds like an ASP.net WebForms control. – Dismissile Nov 15 '10 at 14:56
  • 9
    Webgrid is new in MVC 3 - http://weblogs.asp.net/shijuvarghese/archive/2010/10/08/using-the-webgrid-helper-in-asp-net-mvc-3-beta.aspx – Martin Nov 15 '10 at 17:51

3 Answers3

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.

Einar Arne
  • 236
  • 1
  • 3
  • My grid does not allow this member. Pager not showing. "rowsPerPage" is limiting my grid to this number of rows. – Taersious Feb 01 '17 at 14:44
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).

Martin
  • 11,031
  • 8
  • 50
  • 77
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.

chenriks
  • 121
  • 3