代碼如下:
PagedDataSource objPage = new PagedDataSource();
DataView dv = bllBook.GetListByState("", true);
//設(shè)置數(shù)據(jù)源
objPage.DataSource =dv ;
//允許分頁
objPage.AllowPaging = true;
//設(shè)置每頁顯示的項數(shù)
objPage.PageSize = 10;
//定義變量用來保存當(dāng)前頁索引
int CurPage;
int RecordCount;
int PageCount = objPage.PageCount;
RecordCount = dv.Count;
//判斷是否具有頁面跳轉(zhuǎn)的請求
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurPage = 1;
}
//設(shè)置當(dāng)前頁的索引
objPage.CurrentPageIndex = CurPage - 1;
//顯示狀態(tài)信息
lblCurPage.Text = "第 " + CurPage.ToString() + "/" + PageCount.ToString() + "頁 共 " + RecordCount.ToString() + " 記錄 ";
//如果當(dāng)前頁面不是首頁
if (!objPage.IsFirstPage)
//定義 "上一頁 "超級鏈接的URL為:當(dāng)前執(zhí)行頁面的虛擬路徑,并傳遞下一頁面的索引值
{
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
}
//如果當(dāng)前頁面不是最后一頁
if (!objPage.IsLastPage)
//定義 "下一頁 "超級鏈接的URL為:當(dāng)前執(zhí)行頁面的虛擬路徑,并傳遞下一頁面的索引值
{
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(PageCount);
}
//進行數(shù)據(jù)綁定
Repeater1.DataSource = objPage;
Repeater1.DataBind();
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com