Search code examples
c#asp.net-mvcasp.net-mvc-3webgrid

ASP.NET MVC 3 WebGrid paging issue


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?


Solution

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