• 有用的自定义pagecounter控件


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

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



    源代码下载 /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 主要用于提高性能每次只读取一页的数据

  • 相关阅读:
    [BZOJ] 1623: [Usaco2008 Open]Cow Cars 奶牛飞车
    [BZOJ] 3631: [JLOI2014]松鼠的新家
    [BZOJ] 1775: [Usaco2009 Dec]Vidgame 电视游戏问题
    [BZOJ] 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
    [Codeforces] #432 div.2 (Virtual)
    [BZOJ] 1819: [JSOI]Word Query电子字典
    [Codeforces] #436 E. Fire
    [Codeforces] #436 D. Make a Permutation!
    [Codeforces] #436 C. Bus
    [Codeforces] #436 B. Polycarp and Letters
  • 原文地址:https://www.cnblogs.com/happlyonline/p/808212.html
Copyright © 2020-2023  润新知