如何使用asp.net控件进行DataList分页?
本文实例讲述了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; } }
希望本文所述对大家asp.net程序设计有所帮助。
本文地址:http://www.45fan.com/bcdm/80432.html