ASP.NET MVC 3 WebGrid paging issue

Daniil Harik picture Daniil Harik · Nov 15, 2010 · Viewed 15.8k times · Source

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?

Answer

Einar Arne picture Einar Arne · Dec 30, 2010

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.