C# GridView分页之Excel数据源分页

作者:互联网   出处:控件中国网   2014-11-05 19:21:44   阅读:2

C# GridView分页之Excel数据源分页

    //每页显示的数量
    int PageItem = 5;

    //显示的开始记录,PageIndex当前页码
    int startRecord = (PageIndex - 1) * PageItem;


    sql = "Select * From [Sheet1$]";
    OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
    DataSet ds = new DataSet();
    da.Fill(ds, startRecord, PageItem, "Sheet");

 这样行了,有了数据集,可以绑定了。

    GridView1.DataSource = ds.Tables[0].DefaultView;
    GridView1.DataBind();

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat