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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章