Reputation: 312
I have a simple Webmatrix Razor page with a WebGrid. Paging is set to true and I am showing 100 records per page. Question is, how do I display the record range that each page is showing? For example, at the bottom of page 1 of the grid I want to say 'Displaying records 1 - 100' Then when someone clicks on page 2 of the grid then I want it to say 'Displaying records 101 - 200' and so on.
I searched but can't figure out how to do this. I know how to get the total rows for all pages combined using
grid.TotalRowCount
I can also get rows per page (which in my case is 100 for each one) using
grid.RowsPerPage
Not sure how to get the range of displayed rows per page. I thought about getting the page number of the currently displayed grid page and doing something like this 'Displaying Records: ((grid.RowsPerPage * current page number) - 99) to (grid.RowsPerPage * current page number)
I think the above would work but I don't know how to get the current page number. I was only able to find the option that gave me the total number of pages.
Any help would be greatly appreciated
Upvotes: 1
Views: 1351
Reputation: 15860
Since you know that only 100 would be shown on the page and the numbers of the data that will be presented on the web page. You can edit the footer of the grid and write the details that you will find inside the URL as Mike has stated in the comments,
var currentIndex = UrlData[0];
// or, use Request.QueryString["page"];
// if, URL is like /search?page=1
var endIndex = currentIndex * 100; // results 100, 200, 300...
var startIndex = endIndex - 99; // results 1, 101, 201...
.. expecting the URL to be in form of http://www.example.com/page/1
you can then show it as
<div>
Showing pages from @startIndex to @endIndex.
</div>
This would result in the feature that you're trying to achieve.
Upvotes: 2