Repeater 分页 希望对你有帮助
1.
放个Label1 两个
Button1 Button2
在pagLond 事件里
设成 Label1.Text = "1";
//显示当前页
2. 代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Label1.Text = "1";
getBangDing();
}
}
private void getBangDing()
{
int num = Convert.ToInt32(Label1.Text);
SqlConnection con = new SqlConnection("连接字符串");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("sql语句", con);
DataSet set = new DataSet();
da.Fill(set, "table");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = set.Tables["table"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 3;
int countNum=pds.PageCount;
pds.CurrentPageIndex = num - 1;
Button1.Enabled = true;
Button2.Enabled = true;
if (num == 1)
{
Button1.Enabled = false;
}
if (num == countNum)
{
Button2.Enabled = false;
}
Repeater1.DataSource = pds;
Repeater1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(Convert.ToInt32(Label1.Text) -1); ///上一页
getBangDing();
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(Convert.ToInt32(Label1.Text) + 1);///下一页
getBangDing();
}
[[it] 本帖最后由 蓝色畅想 于 2008-7-1 00:23 编辑 [/it]]