有用的自訂pagecounter控制項

來源:互聯網
上載者:User

概述
在實際的系統開發過程中經常會遇到系統內建的分頁控制項不能滿足要求或者其樣式太單一,需要自訂開發分頁控制項的情況,這個功能雖然很小但是很實用.

是這個自訂控制項的顯示

原始碼下載 /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 主要用於提高效能每次唯讀取一頁的資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.