SQL Server - Need help in displaying data in gridview dynamically

Asked By Sumit Kumar on 26-Jan-10 01:59 AM
Hi all,

Pls somebody give me the solutions. Suppose i have data in database table. I wanna display all the field with data in gridview. In database table i have 1000 rows of data. But in gridview in one page can hold only 50 rows. So when i click on page 2 in gridview it should display next 50 rows....then again if click on page 3, gridview should display next 50 rows...like this it will continue. I don't want all the rows(1000 rows) to be loaded at a time. It should load dynamically everytime 50 rows only.. Pls give me the solution, how do i achieve it with code..

Thanks,

Sumit



Check this out. - Michael Detras replied to Sumit Kumar on 26-Jan-10 02:58 AM

Create a stored procedure with the body which is something like the following:

WITH ORDERED AS

(

    SELECT *, ROW_NUMBER()

    OVER (ORDER BY ID ASC) AS ROWNUMBER

    FROM MYTABLE

)

SELECT * FROM ORDERED

WHERE ROWNUMBER BETWEEN 1 AND 50

Just replace the constants 1 and 50 with the stored procedure arguments, like Start and End. Hope this helps.

Dynamic Server Side Pagination - F Cali replied to Sumit Kumar on 26-Jan-10 08:02 AM

Just in case you are using SQL Server 2000 as your database, here's a link that shows how to do an efficient and dynamic server-side pagination with SQL Server 2000:

http://weblogs.sqlteam.com/jeffs/archive/2004/03/22/1085.aspx

Regards,
http://www.sql-server-helper.com/error-messages/msg-107.aspx