高效的GridView分页...不太明白 [英] Efficient GridView Paging... not quite getting it

查看:81
本文介绍了高效的GridView分页...不太明白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ASP.NET Gridview中将自定义分页包裹起来,但是我读的所有示例似乎都与我不需要的东西臃肿( Scott Gu )。



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

有人可以指向我正确的方向来阅读易于理解基础知识的教程吗? / p>

 更改过程dbo.GetReqeusts 

@Category nvarchar(50)

作为
开始
选择dbo。[Name],
dbo。[ID]
从dbo。[Table]
Where dbo。[Category] ​​= @Category
结束

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

解决方案

4guysfromrolla.com有一系列关于处理和显示数据。有几个关于自定义分页的内容。



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

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


I'm trying to wrap my head around custom paging in the ASP.NET Gridview, but all of the examples I read seem to be bloated with stuff I don't need (Scott Gu's for example).

Can someone point me in the right direction to a tutorial that is easy to understand the basics?

EXAMPE: If I have the following Stored Procedure...

Alter Procedure dbo.GetReqeusts

@Category nvarchar(50)

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

And this example returns 200 rows, how would I convert this Stored Procedure into an efficient paging procedure?

解决方案

4guysfromrolla.com have a whole series of articles about working with and displaying data. There are several about custom paging.

The key point for the stored procedure is to use the ROW_NUMBER() function to restrict the records to be returned:

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

这篇关于高效的GridView分页...不太明白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆