12-7 GridView分页

按钮的属性:

 

显示这是第几页一共几页

 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();
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值