復制代碼 代碼如下:
PagedDataSource objPage = new PagedDataSource();
DataView dv = bllBook.GetListByState("", true);
//設置數據源
objPage.DataSource =dv ;
//允許分頁
objPage.AllowPaging = true;
//設置每頁顯示的項數
objPage.PageSize = 10;
//定義變量用來保存當前頁索引
int CurPage;
int RecordCount;
int PageCount = objPage.PageCount;
RecordCount = dv.Count;
//判斷是否具有頁面跳轉的請求
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurPage = 1;
}
//設置當前頁的索引
objPage.CurrentPageIndex = CurPage - 1;
//顯示狀態信息
lblCurPage.Text = "第 " + CurPage.ToString() + "/" + PageCount.ToString() + "頁 共 " + RecordCount.ToString() + " 記錄 ";
//如果當前頁面不是首頁
if (!objPage.IsFirstPage)
//定義 "上一頁 "超級鏈接的URL為:當前執行頁面的虛擬路徑,並傳遞下一頁面的索引值
{
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
}
//如果當前頁面不是最後一頁
if (!objPage.IsLastPage)
//定義 "下一頁 "超級鏈接的URL為:當前執行頁面的虛擬路徑,並傳遞下一頁面的索引值
{
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(PageCount);
}
//進行數據綁定
Repeater1.DataSource = objPage;
Repeater1.DataBind();