简单DataList分页,使用PagedDataSource
protected void Page_Load(object sender, EventArgs e)
{
//对PagedDataSource 对象的相关属性赋值
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ObjectDataSource1.Select();
objPds.AllowPaging = true;
objPds.PageSize = 1;
int CurPage;
//当前页面从Page查询参数获取
if (Request.QueryString["Page"] != null)
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage = 1;
objPds.CurrentPageIndex = CurPage - 1;
lblCurrentPage.Text = "当前页码: " + CurPage.ToString() + "/" + objPds.PageCount;
if (!objPds.IsFirstPage)
lnkPrev.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
if (!objPds.IsLastPage)
lnkNext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
//把PagedDataSource 对象赋给Repeater控件
DataList1.DataSourceID = "";
DataList1.DataSource = objPds;
DataList1.DataBind();
}