1: 在页面中添加四个按钮(Button或ImageButton)分别为: [首页][上一页][下一页][末页],并且设置四个的OnClick事件都为一样.如:都是 button_click (四个按钮都调用同一个 button_click 事件)
2:为四个按钮的CommandArgument事件分别取名,如:"first","up","next","last"
3:后台代码:(注意:四个按钮都是用button_click这一个事件, 直接在四个按钮的click事件中输入button_click)
protected void button_click(object sender, EventArgs e)
{
string commandString = ((Button)sender).CommandArgument.ToString();
switch (commandString)
{
case "next":
if (this.GridView1.PageIndex < (GridView1.PageCount - 1))
{
GridView1.PageIndex += 1;
}
break;
case"up":
if (this.GridView1.PageIndex > 0)
{
GridView1.PageIndex -= 1;
}
break;
case"last":
this.GridView1.PageIndex = (GridView1.PageCount - 1);
break;
case"first":
this.GridView1.PageIndex = 0;
break;
}
bindGridView(); //重新绑定
}
4:同时还要设置GridView的AllowPaging="True" 以及PageSize 页数.
在HTML设置中去掉 <PagerSettings Visible="false" />
的分页效果..