using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
public partial class Repeater_1 : System.Web.UI.Page
{
// MySqlConnection mysqlconnection = Conn.createCon();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Label1.Text = "1";
databindToRepeater();
}
//data_Repeater();
}
private void databindToRepeater()
{
int curPage = Convert.ToInt32(this.Label1.Text);
MySqlConnection mysqlconnection = Conn.createCon();
MySqlDataAdapter dataAdapter2 = new MySqlDataAdapter("select * from bookinfo", mysqlconnection);
DataSet ds = new DataSet();
dataAdapter2.Fill(ds, "emp");
//分页
System.Web.UI.WebControls.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 = ds.Tables["emp"];
this.Repeater1.DataSource = ps;
this.Repeater1.DataBind();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
}
protected void button1_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text)-1);
databindToRepeater();
}
protected void button2_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) +1);
databindToRepeater();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
public partial class Repeater_1 : System.Web.UI.Page
{
// MySqlConnection mysqlconnection = Conn.createCon();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Label1.Text = "1";
databindToRepeater();
}
//data_Repeater();
}
private void databindToRepeater()
{
int curPage = Convert.ToInt32(this.Label1.Text);
MySqlConnection mysqlconnection = Conn.createCon();
MySqlDataAdapter dataAdapter2 = new MySqlDataAdapter("select * from bookinfo", mysqlconnection);
DataSet ds = new DataSet();
dataAdapter2.Fill(ds, "emp");
//分页
System.Web.UI.WebControls.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 = ds.Tables["emp"];
this.Repeater1.DataSource = ps;
this.Repeater1.DataBind();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
}
protected void button1_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text)-1);
databindToRepeater();
}
protected void button2_Click(object sender, EventArgs e)
{
this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) +1);
databindToRepeater();
}
}
本文介绍了一个使用ASP.NET和MySQL实现的数据分页及Repeater控件数据绑定的例子。通过建立数据库连接并填充数据集,利用PagedDataSource组件实现了每页显示三条记录的分页效果,并提供了前后翻页的功能。
1019

被折叠的 条评论
为什么被折叠?



