按钮的属性:
显示这是第几页一共几页
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row .RowType ==DataControlRowType .Pager )
{
(e.Row.Cells[0].FindControl("Label1") as Label).Text = "第" + (GridView1.PageIndex + 1).ToString() + "页,共" + GridView1.PageCount + "页";
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindStudent();
}
}
private void BindStudent()
{
string sql = "select * from student";
DataTable dt = SqlHelper.Executedatatable (sql);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
this.GridView2.DataSource = dt;
this.GridView2.DataBind();
}
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
if (e.NewPageIndex >= 0)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.BindStudent();
}
}
protected void Button5_Click(object sender, EventArgs e)
{
this.GridView2.PageIndex = 0;
this.BindStudent();
}
protected void Button6_Click(object sender, EventArgs e)
{
this.GridView2.PageIndex = this.GridView2.PageCount - 1;
this.BindStudent();
}
protected void Button7_Click(object sender, EventArgs e)
{
int index = this.GridView2.PageIndex;
if (index >= 1)
{
index--;
}
this.GridView2.PageIndex = index;
this.BindStudent();
}
protected void Button8_Click(object sender, EventArgs e)
{
int index = this.GridView2.PageIndex;
if (index < this.GridView2.PageCount + 1)
{
index++;
}
this.GridView2.PageIndex = index;
this.BindStudent();
}