ASP.NET MVC 3 WebGrid paging issue

15,893

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
15,893
Daniil Harik
Author by

Daniil Harik

Hei,

Updated on June 27, 2022

Comments

  • Daniil Harik
    Daniil Harik almost 2 years

    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?