AspNetPager的用法

來源:互聯網
上載者:User

public partial class PagedIndex4 : System.Web.UI.Page
{  
    private Current_db db = new Current_db();
    SqlConnection conn;
    SqlCommand cmd;
    private void Page_Load(object sender, System.EventArgs e)
    {
        conn = new SqlConnection("Server = 192.168.1.15;database=my_sz5_cn;uid=skyray;pwd=skyray");

        if (!Page.IsPostBack)
        {
            cmd = new SqlCommand("select count(*) from info_information",conn);
            conn.Open();
            //設定要分頁的資料的總數  
            lbtotal.Text = cmd.ExecuteScalar().ToString();
              AspNetPager1.RecordCount = (int)cmd.ExecuteScalar();
             lbs.Text = AspNetPager1.PageSize.ToString();
            //int PageCount = AspNetPager1.RecordCount / AspNetPager1.PageSize+1;
            //lbPages.Text = PageCount.ToString();
            conn.Close();
            //綁定資料  
            BindData();
        }    
    }

    void BindData()
    {
        cmd = new SqlCommand("select top 10000 * from info_information", conn);
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        //注意下面這句,只填充當前頁要顯示的資料,不能把所有資料全填充到DataSet中,否則無法實現分頁  
        adapter.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSiz  e, "info_information");
        GridView1.DataSource = ds.Tables["info_information"];
        GridView1.DataBind();
    }

    //翻頁事件處理常式,設定分頁控制項的當前頁索引並重新綁定資料
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindData();
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.