实现 Repeater 控件和 DataList 控件的分页 !!!
源文件:(还需要自己添加上 Repeater(id=rptList) 控件 !)
<div style="padding: 5px; padding-left:10px; background-color: #dedede; 88%">
<asp:Label ID="lblPages" runat="server" Text="Label" ForeColor="#444444"></asp:Label>
<asp:Label ID="lblCurrentPage" runat="server" ForeColor="#444444"></asp:Label>
<asp:HyperLink ID="lnkPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink ID="lnkNext" runat="server">下一页</asp:HyperLink>
</div>
=================================================================================================
.CS 文件:
//实现 Repeater 分页 !!!
private void SelectNewsListBySortID(int sortID)
{
PagedDataSource pds = new PagedDataSource();
DataTable dt = CatalogAccess.SelectNewsListBySortID(sortID);
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 3;
int curPage;
if (Request.QueryString["Page"] != null)
{
curPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
curPage = 1;
}
pds.CurrentPageIndex = curPage - 1;
lblPages.Text = " 共 " + Convert.ToString(pds.PageCount) + " 页 ";
lblCurrentPage.Text = "当前第 " + curPage.ToString() + " 页 ";
if (pds.PageCount == 1)
{
this.lnkPrev.Visible = false;
this.lnkNext.Visible = false;
}
else
{
if (!pds.IsFirstPage)
{
if (pds.IsLastPage)
{
lnkNext.Visible = false;
}
lnkPrev.Visible = true;
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?SortID=1&id=" + id +
"&DetailsID=0&Page=" + Convert.ToString(curPage - 1); //棕色字体根据实际情况修改
}
if (!pds.IsLastPage)
{
if (pds.IsFirstPage)
{
lnkPrev.Visible = false;
}
lnkNext.Visible = true;
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?SortID=1&id=" + id +
"&DetailsID=0&Page=" + Convert.ToString(curPage + 1);
}
}
rptList.DataSource = pds;
rptList.DataBind();
}