首页 > 代码库 > Repeater分页
Repeater分页
一、页面上放置2个标签(lbl)分别显示当前页和总页数 ,然后再放置4个linkbutton分别表示 首页,下一页,上一页,末页
二、自己做一个分页的方法:
public void contrlRepeater()
{
string sql = "select * from dbo.tb_Reply where ReplyID=" + this.Request.QueryString["lyid"].ToString() + "";
DataTable dt = db.GetT(sql);
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true; //允许分页
pds.PageSize = 2; //每页记录数
pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
Repeater1.DataSource = pds; //绑定数据源到分页类
LabCountPage.Text = pds.PageCount.ToString();
labPage.Text = (pds.CurrentPageIndex + 1).ToString();
this.lbtnpritPage.Enabled = true;
this.lbtnFirstPage.Enabled = true;
this.lbtnNextPage.Enabled = true;
this.lbtnDownPage.Enabled = true;
if (pds.CurrentPageIndex < 1)
{
this.lbtnpritPage.Enabled = false;
this.lbtnFirstPage.Enabled = false;
}
if (pds.CurrentPageIndex == pds.PageCount - 1)
{
this.lbtnNextPage.Enabled = false;
this.lbtnDownPage.Enabled = false;
}
Repeater1.DataBind();
}
三、LOAD事件调用
if (!IsPostBack) //如果页面不是回发
{
this.labPage.Text = "1";
contrlRepeater();
}
四、写4个按钮的单击事件
protected void lbtnpritPage_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) - 1);
this.contrlRepeater();
}
protected void lbtnFirstPage_Click(object sender, EventArgs e)
{
this.labPage.Text = "1";
this.contrlRepeater();
}
protected void lbtnDownPage_Click(object sender, EventArgs e)
{
this.labPage.Text = this.LabCountPage.Text;
this.contrlRepeater();
}
protected void lbtnNextPage_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) + 1);
this.contrlRepeater();
}