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

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


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

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

有用的自定义pagecounter控件int page = 1;
有用的自定义pagecounter控件page 
= Convert.ToInt32(Page.Request.QueryString["page"]);
有用的自定义pagecounter控件PagerCounter.PageIndex 
= page;
有用的自定义pagecounter控件PagerCounter.PageSize 
= 20;
有用的自定义pagecounter控件PagerCounter.UrlFormat 
= Page.Request.Url.AbsolutePath + "?page={0}";
有用的自定义pagecounter控件PagerCounter.ItemCount 
= Count;
有用的自定义pagecounter控件

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

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

 有用的分页存储过程

有用的自定义pagecounter控件CREATE procedure sys_getpagerrecord
有用的自定义pagecounter控件(
有用的自定义pagecounter控件
@strSql Varchar(3000),    --传入的Sql语句

有用的自定义pagecounter控件
@pagesize int,      --页面大小,如每页存储20条记录
有用的自定义pagecounter控件
@pageindex int      --当前页码
有用的自定义pagecounter控件
)
有用的自定义pagecounter控件
as

有用的自定义pagecounter控件
set nocount on
有用的自定义pagecounter控件
begin
有用的自定义pagecounter控件
declare @PageLowerBound int  --定义此页的底码
有用的自定义pagecounter控件
declare @PageUpperBound int  --定义此页的顶码
有用的自定义pagecounter控件
declare @execSql varchar(3000)
有用的自定义pagecounter控件
有用的自定义pagecounter控件
set @PageLowerBound = (@pageindex-1* @pagesize

有用的自定义pagecounter控件
set @PageUpperBound = @PageLowerBound + @pagesize
有用的自定义pagecounter控件
set rowcount @PageUpperBound
有用的自定义pagecounter控件
create table #IndexTable (id int Identity(1,1) , autoInc varchar(500))
有用的自定义pagecounter控件
set @execSql = 'insert into #IndexTable (autoInc) select autoInc from (' +  @strSql + ') as tempview'

有用的自定义pagecounter控件
print @execSql
有用的自定义pagecounter控件
exec(@execSql)
有用的自定义pagecounter控件
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'

有用的自定义pagecounter控件
print @execSql
有用的自定义pagecounter控件
exec(@execSql)
有用的自定义pagecounter控件
end

有用的自定义pagecounter控件
set nocount off
有用的自定义pagecounter控件
GO
有用的自定义pagecounter控件

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2021-05-15
猜你喜欢
  • 2021-12-15
  • 2021-11-18
  • 2021-12-18
  • 2021-11-04
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案