高效的GridView分页...不太明白

时间:2010-02-28 22:22:21

标签: asp.net sql gridview

我正试图在ASP.NET Gridview中绕过自定义分页,但我读到的所有示例似乎都充满了我不需要的东西(例如Scott Gu

有人能指出我正确的方向指向易于理解基础知识的教程吗?

EXAMPE:如果我有以下存储过程......

Alter Procedure dbo.GetReqeusts

@Category nvarchar(50)

As
Begin
  Select dbo.[Name], 
         dbo.[ID] 
  From   dbo.[Table] 
  Where  dbo.[Category] = @Category
End

此示例返回200行,如何将此存储过程转换为有效的分页过程?

1 个答案:

答案 0 :(得分:2)

4guysfromrolla.com有一系列关于working with and displaying data的文章。有几个关于custom paging

存储过程的关键是使用ROW_NUMBER()函数来限制要返回的记录:

SELECT RowNum, [Name], [ID]
FROM
   (SELECT [Name], [ID]
         ROW_NUMBER() OVER(ORDER BY [ID]) as RowNum
    FROM [Table] t
    WHERE [Category] = @Category
   ) as DerivedTableName
WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex + @maximumRows) - 1