开发者

Implementing numeric pagination with asp.net

Hai guys, I have nearly 20 pages in my website .... Every page has a gridview which has thousands of records bind to it... Now i want to implement custom pagination to all those grids.... Guys can some one give a pagination class which can be reusable for a开发者_Go百科ll those pages


Your not really going to get a one size fits all class to do this, thats why its called custom paging.

Just a rough guide as to how I have implemented this in the past.

Store the current page number somewhere Querystring/Session/Wherever

When you call your data method/stored procedure to ask for the data pass in the page number and amount of records per page you want.

ammend you stored procedure/data method to only return records in these bounds, it will also need to return a count of the total records so the application knows how many pages there are.

Here is simple example of how you could achieve paging in your stored procedures using SQL2005/2008 (Slightly more to it in 2000)

CREATE PROCEDURE GetTowns
(
@OutTotalRecCount INT OUTPUT,
@CurrentPage INT,
@PageSize INT
)
AS

    SELECT * FROM     
     (
     SELECT 
      ROW_NUMBER() OVER (ORDER BY TownName) AS Row, 
      TownId,
      TownName
     FROM Towns
     ) AS TownsWithRowNumbers
    WHERE  Row >= (@CurrentPage - 1) * @PageSize + 1 AND Row <= @CurrentPage*@PageSize

    SELECT @OutTotalRecCount = COUNT(*) FROM Towns


Not sure about a "class", but here are a couple of links:

.NET 3.5

.NET 2.0

p.s. If you use DataSet as your DataSource, paging and sorting is supported out of the box.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜