鸡毛信
征服世界,并不伟大,一个人能征服自己,才是世界上最伟大的人。

概述
在实际的系统开发过程中经常会遇到系统自带的分页控件不能满足要求或者其样式太单一,需要自定义开发分页控件的情况,这个功能虽然很小但是很实用.

下图是这个自定义控件的显示



源代码下载 /Files/happlyonline/PageCounter.rar

使用
在使用这个pagecounter的页面给pagecounter控件的当前页,页大小,数据源的总count数的属性赋值即可.

int page = 1;
page 
= Convert.ToInt32(Page.Request.QueryString["page"]);
PagerCounter.PageIndex 
= page;
PagerCounter.PageSize 
= 20;
PagerCounter.UrlFormat 
= Page.Request.Url.AbsolutePath + "?page={0}";
PagerCounter.ItemCount 
= Count;

在页面换页后IE中的URL地址会改变为 http://xxx/xxx/xx.aspx?page=2, 所以在使用的时候需要考虑实际情况稍加修改

在gridview中使用自定义的分页控件
由于gridview提供了<PagerTemplate>的模版列,可根据实际情况在这里写自定义的分页控件

 有用的分页存储过程

CREATE procedure sys_getpagerrecord
(
@strSql Varchar(3000),    --传入的Sql语句

@pagesize int,      --页面大小,如每页存储20条记录
@pageindex int      --当前页码
)
as

set nocount on
begin
declare @PageLowerBound int  --定义此页的底码
declare @PageUpperBound int  --定义此页的顶码
declare @execSql varchar(3000)

set @PageLowerBound = (@pageindex-1* @pagesize

set @PageUpperBound = @PageLowerBound + @pagesize
set rowcount @PageUpperBound
create table #IndexTable (id int Identity(1,1) , autoInc varchar(500))
set @execSql = 'insert into #IndexTable (autoInc) select autoInc from (' +  @strSql + ') as tempview'

print @execSql
exec(@execSql)
set @execSql = 'select * from (' + @strSql + ') as tempview inner join #IndexTable as b on tempview.autoInc = b.autoInc where b.id>' + str(@PageLowerBound+ ' and b.id<=' + str(@PageUpperBound+ ' order by b.id'

print @execSql
exec(@execSql)
end

set nocount off
GO

在这里set rowcount 主要用于提高性能每次只读取一页的数据

posted on 2007-07-06 11:40  鸡毛信  阅读(334)  评论(0编辑  收藏  举报