此分页控件是采用后台存储过程分页,每次只取一页的数据。当然,物不尽美,同样数据量很大的时候,也会增加数据库的负担,因每次翻页的时候,都要与数据库进行交互!
一、存储过程

在Asp.net中自定义的分页控件CREATE      PROCEDURE [dbo].[PageData_P] 
在Asp.net中自定义的分页控件
@sqlstr nvarchar(3500),     --SQL字符串
在Asp.net中自定义的分页控件
@curpage int,        --第N页
在Asp.net中自定义的分页控件
@pagesize int        --每页行数
在Asp.net中自定义的分页控件
AS
在Asp.net中自定义的分页控件
begin
在Asp.net中自定义的分页控件
在Asp.net中自定义的分页控件
set nocount on
在Asp.net中自定义的分页控件
declare @P1 int,        --P1是游标的id
在Asp.net中自定义的分页控件
        @rowcount int@pagecount int
在Asp.net中自定义的分页控件
SET @sqlstr = RTRIM(@sqlstr)
在Asp.net中自定义的分页控件
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
在Asp.net中自定义的分页控件
set @pagecount = ceiling(1.0*@rowcount/@pagesize)
在Asp.net中自定义的分页控件
if @curpage<=1
在Asp.net中自定义的分页控件    
set @curpage =1
在Asp.net中自定义的分页控件
if @curpage>@pagecount
在Asp.net中自定义的分页控件    
set @curpage=@pagecount
在Asp.net中自定义的分页控件
select @rowcount as Total, @pagecount as PageCount,@curpage as CurPage    
在Asp.net中自定义的分页控件
set @curpage=(@curpage-1)*@pagesize+1
在Asp.net中自定义的分页控件
exec sp_cursorfetch @P1,16,@curpage,@pagesize 
在Asp.net中自定义的分页控件
exec sp_cursorclose @P1
在Asp.net中自定义的分页控件
end
在Asp.net中自定义的分页控件
GO

二、在项目中新增一用户控件,命名为Pager.ascx
1、页面代码为: 

>


2、CS代码部分:

在Asp.net中自定义的分页控件namespace MyLibrary.UserControl
}

三、用法与事例
#endregion

 

相关文章: