- 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 RepeaterDataBind : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- this.Label2.Text = "1";
- this.dataBindToRepeater();
- }
- }
- private void dataBindToRepeater()
- {
- int curPage = Convert.ToInt32(this.Label2.Text);
- SqlConnection con = DB.createCon();
- SqlDataAdapter sdr = new SqlDataAdapter();
- sdr.SelectCommand = new SqlCommand("select * from Employees", con);
- DataSet ds = new DataSet();
- sdr.Fill(ds, "emp");
- PagedDataSource ps = new PagedDataSource();
- ps.DataSource = ds.Tables["emp"].DefaultView;
- ps.AllowPaging = true;
- ps.PageSize = 3;
- ps.CurrentPageIndex = curPage - 1;
- this.Button1.Enabled = true;
- this.Button2.Enabled = true;
- if (curPage == 1)
- {
- this.Button1.Enabled = false;
- }
- if (curPage == ps.PageCount )
- {
- this.Button2.Enabled = false;
- }
- this.Repeater1.DataSource = ps;
- this.Repeater1.DataBind();
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- this.Label2.Text=""+(Convert.ToInt32(this.Label2.Text)-1);
- this.dataBindToRepeater();
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- this.Label2.Text = ""+(Convert.ToInt32(this.Label2.Text) + 1);
- this.dataBindToRepeater();
- }
- }
使用Repeater实现分页显示
最新推荐文章于 2013-11-04 15:30:42 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)