public void dlBind()
{
int curpage = Convert.ToInt32(labNowPage.Text);
PagedDataSource ps = new PagedDataSource();
SqlConnection mycon = datacon.greatecon();
mycon.Open();
SqlDataAdapter MyAdapter = new SqlDataAdapter("select * from [user]", mycon);
DataSet ds = new DataSet();
MyAdapter.Fill(ds, "user");
ps.DataSource = ds.Tables["user"].DefaultView;
//ps.DataSource = opends("user").Tables["user"].DefaultView;
ps.AllowPaging = true; //是否可以分页
ps.PageSize = 6; //显示的数量0
ps.CurrentPageIndex = curpage - 1; //取得当前页的页码
lnkbtnPrve.Enabled = true;
lnkbtnTop.Enabled = true;
lnkbtnNext.Enabled = true;
lnkbtnLast.Enabled = true;
if (curpage == 1)
{
lnkbtnTop.Enabled = false;//不显示第一页按钮
lnkbtnPrve.Enabled = false;//不显示上一页按钮
}
if (curpage == ps.PageCount)
{
lnkbtnNext.Enabled = false;//不显示下一页
lnkbtnLast.Enabled = false;//不显示最后一页
}
this.labCount.Text = Convert.ToString(ps.PageCount);
this.gridview1.DataSource = ps;
this.gridview1.DataBind();
}
//首页
protected void lnkbtnTop_Click(object sender, EventArgs e)
{
this.labNowPage.Text = "1";
this.dlBind();
}
//上一页
protected void lnkbtnPrve_Click(object sender, EventArgs e)
{
this.labNowPage.Text = Convert.ToString(Convert.ToInt32(this.labNowPage.Text) - 1);
this.dlBind();
}
//下一页
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
this.labNowPage.Text = Convert.ToString(Convert.ToInt32(this.labNowPage.Text) + 1);
this.dlBind();
}
//尾页
protected void lnkbtnLast_Click(object sender, EventArgs e)
{
this.labNowPage.Text = this.labCount.Text;
this.dlBind();
}
试试这个代码