分頁技術之PageDataSource類

2022-05-15 10:03:36 字數 1114 閱讀 4469

之前給大家介紹了分頁技術之gridview控制項,今天給大家介紹另外一種分頁技術,採用pagedatasource類 + repeater控制項來實現。

前台只需要拖出乙個repeater控制項來繫結要顯示資料即可。

後台**的實現具體步驟如下:

第一步:連線資料庫獲取要顯示的內容

//連線資料庫及將資料封裝到乙個資料集中

db db = new db();

dataset ds = db.getdataset ( sql );

//將dataset繫結到pagedatasource

pageddatasource ps = new pageddatasource();

ps.datasource = ds.tables[0].defaultview;

//設定屬性為允許分頁

ps.allowpaging = true;

//獲取當前頁面數

int curpage;

if (request.querystring["page"] != null) //當前請求頁面

curpage = convert.toint32(request.querystring["page"]);

else

curpage = 1;

//每個頁面顯示的條數

ps.pagesize = 20;

//求資料的總數

allmsg.text = ps.datasourcecount.tostring();

ps.currentpageindex = curpage - 1;

//求總頁數

allpages.text = ps.pagecount.tostring();

nowpage.text = curpage.tostring();

第三步:將資料來源繫結到repeater控制項

//將資料來源與控制項繫結

repeater1.datasource = ps;

repeater1.databind();

if (!ps.isfirstpage)

if (!ps.islastpage)

分頁技術之經驗

前言 在bs開發上不可避免地要實現分頁處理,分頁處理目前來說基本是兩種處理方式 資料庫分頁和記憶體分頁。資料庫分頁 資料庫分頁 利用資料庫提供的分頁查詢功能實現,如在mysql3中的查詢 select from employee where dept id d11 limit 10,20 這兒利用l...

分頁技術之GridView控制項

5455 5657 5859 view code gridview container.parent.parent pageindex 1獲取當前控制項顯示的頁面數 gridview container.parent.parent pagecount獲取當前控制項總的頁面數 causesvalida...

sql 分頁 後台分頁技術

select stunumber,stuname,case when stumath 90then 優 when stumath 80then 良 when stumath 70then 中 else 差 end as 數學成績 from tbstudent 第一種用法 case語句就是構造乙個新的...