Repeater分页显示

时间:2013-12-20 11:29:56
【文件属性】:

文件名称:Repeater分页显示

文件大小:46KB

文件格式:DOC

更新时间:2013-12-20 11:29:56

Repeater分页显示

Repeater分页显示 简单的说,先从控件工具箱中拖入两个label(currten page当前页,count page总页),四个linkbuttion(首/下页/上页/尾页)。 无非就是+1 -1 的问题, ------------------------ using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class gonggao : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.labPage.Text = "1"; this.contrlRepeater(); } } //获取指字符个数的字符 public string cuts(string aa,int bb) { if (aa.Length <= bb) { return aa; } else { return aa.Substring(0, bb); } } //Repeater分页控制显示方法 public void contrlRepeater() { pb pb1 = new pb(); DataSet ss = new DataSet(); ss = pb1.returnDs("select top 200 [标题],[时间] from news"); PagedDataSource pds = new PagedDataSource(); pds.DataSource = ss.Tables["temptable"].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(); } 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(); } } -----------------


网友评论