Last post Dec 22, 2014 03:40 PM by thsman
Dec 22, 2014 02:58 PM|thsman|LINK
So I have a gridview with which I'm using Declan Bright's nifty responsive grid plugin
It works very well. But there is a problem with it when the page limit of the gridview is set so low that the number of pages exceeds 10. Then the plugin is pointless. I believe users using a phone to access the site would be happy with a 10 per page limit
as it appears to make the grid more useable on a phone to me. But I then have to limit the number of records selected so that the paging controls don't fill the width of the screen.
I know I can use SELECT TOP to pull a smaller number of records and this will even work quite rapidly which is another plus. What I don't know how to do is select the first 10 records and then the next 10 etc. So that is my question. How to pull all the
records in increments of 10 at a time?
Dec 22, 2014 03:05 PM|wim sturkenboom|LINK
The basics (in stored procedure form); modify to your needs. This only works on SQL server 2012 or newer.
ALTER PROCEDURE [dbo].[usp_Groups_GetPaged]
select * from Groups
order by GroupName asc
OFFSET @pFirstrow ROWS
FETCH NEXT @pNumrows ROWS ONLY
@pFirstrow is the first row that you want to retrieve (zero based)
@pNumrows is the number of rows to retrieve.
An 'order by' clause is required.
In the code behind, you simply modify @pFirstrow to retrieve another (next, previous, first, last) set of records.
For earlier versions of Sql Server, you can refer to the solution her:
Dec 22, 2014 03:40 PM|thsman|LINK
Thank you very much.