DataGridView翻页

。net翻页很简单,主要解决两个问题,记录当前页,绑定数据。

/// <summary>
    /// 首页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtFirstPage_Click(object sender, EventArgs e)
    {
        lbtNextPage.Enabled = true;
        lbtLastPage.Enabled = true;

        lbtPreviewPage.Enabled = false;
        lbtFirstPage.Enabled = false;

        hfCurrentPage.Value = "1";
        ddlCurrenPage.SelectedValue = hfCurrentPage.Value;

        DBModule dbm = DBModule.Instance();

        GridViewLBJ.PageIndex = 0;
        GridViewLBJ.DataSource = dbm.DataTableOfLBJ;
        GridViewLBJ.DataBind();
    }

    /// <summary>
    /// 前一页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtPreviewPage_Click(object sender, EventArgs e)
    { 
        lbtNextPage.Enabled = true;
        lbtLastPage.Enabled = true;

        int count = Convert.ToInt32(hfCurrentPage.Value);
        count--;
        hfCurrentPage.Value = count.ToString();
        ddlCurrenPage.SelectedValue = hfCurrentPage.Value;
        if (count == 1)
        {
            lbtPreviewPage.Enabled = false;
            lbtFirstPage.Enabled = false;
        }

        DBModule dbm = DBModule.Instance();

        GridViewLBJ.PageIndex = count - 1;
        GridViewLBJ.DataSource = dbm.DataTableOfLBJ;
        GridViewLBJ.DataBind();
    }

    /// <summary>
    /// 下一页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtNextPage_Click(object sender, EventArgs e)
    {   
        lbtPreviewPage.Enabled = true;
        lbtFirstPage.Enabled = true;

        int count = Convert.ToInt32(hfCurrentPage.Value);
        int sumCount = Convert.ToInt32(hfSumPage.Value);
        count++;
        hfCurrentPage.Value = count.ToString();
        ddlCurrenPage.SelectedValue = hfCurrentPage.Value;
        if (count == sumCount)
        {
            lbtNextPage.Enabled = false;
            lbtLastPage.Enabled = false;
        }

        DBModule dbm = DBModule.Instance();

        GridViewLBJ.PageIndex = count - 1;
        GridViewLBJ.DataSource = dbm.DataTableOfLBJ;
        GridViewLBJ.DataBind();
    }

    /// <summary>
    /// 末页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtLastPage_Click(object sender, EventArgs e)
    {
        lbtPreviewPage.Enabled = true;
        lbtFirstPage.Enabled = true;

        lbtNextPage.Enabled = false;
        lbtLastPage.Enabled = false;

        hfCurrentPage.Value = hfSumPage.Value;
        ddlCurrenPage.SelectedValue = hfCurrentPage.Value;

        DBModule dbm = DBModule.Instance();

        GridViewLBJ.PageIndex = Convert.ToInt32(hfSumPage.Value) - 1;
        GridViewLBJ.DataSource = dbm.DataTableOfLBJ;
        GridViewLBJ.DataBind();
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值