本文实例讲述了asp.net控件DataList分页用法。分享给大家供大家参考,具体如下:
protected void Page_Load(object sender, EventArgs e){ if (!IsPostBack) { ViewState["Page"] = 0; Bangding(); }}//绑定数据public void Bangding(){ PagedDataSource pds = new PagedDataSource(); pds.DataSource = MerchandiseManager.GetList(""); pds.AllowPaging = true; pds.PageSize = 5; //每页记录数 pds.CurrentPageIndex = Pager;//当前页 lblCurrPage.Text = "第" + (pds.CurrentPageIndex + 1).ToString() + "页 共" + pds.PageCount.ToString() + "页"; SetEnable(pds);//上下页按钮的有效壮态 dlistMerchand.DataSource = pds; dlistMerchand.DataBind();}private int Pager{ get { return (int)ViewState["Page"]; } set { ViewState["Page"] = value; }}//下一页protected void LinkButton1_Click(object sender, EventArgs e){ Pager++; Bangding();}//上一页protected void LinkButton2_Click(object sender, EventArgs e){ Pager--; Bangding();}//上下页按钮的有效壮态private void SetEnable(PagedDataSource pds){ btnShang.Enabled = true; btnXia.Enabled = true; if (pds.IsFirstPage) { btnShang.Enabled = false; } if (pds.IsLastPage) { btnXia.Enabled = false; }}