Repeater控件分页例子
Repeater和DataList控件提供了一个快速、灵活的表现数据的方式,但是,它们没有内建的分页功能;DataGrid控件提供了内建的分页功能,但它的结构比较复杂。下面就用PagedDataSource类实现Repeater和DataList的分页。 PagedDataSource封装了DataGrid的分页属性,我们可以象DataGrid那样进行分页。代码如下:
C#版本
DataTable table = new AdminUserBLL().ListAdmin();
PagedDataSource objPage = new PagedDataSource();
objPage.AllowPaging = true;
objPage.DataSource = table.DefaultView;
objPage.PageSize = 10;
int CurPage;
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurPage = 1;
}
objPage.CurrentPageIndex = CurPage - 1;
lblCurrentPage.Text = "当前页:" + CurPage.ToString()+"/共"+objPage.PageCount.ToString()+"页";
if (!objPage.IsFirstPage)
{
lnkPrev.Text = "<a href=" + Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + ">上一页</a>";
}
if (!objPage.IsLastPage)
{
lnkNext.Text = "<a href=" + Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + ">下一页</a>";
}
User_List.DataSource = objPage;
User_List.DataBind();