//每页显示的数量
    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();

可以将上面的方法写为公共类的公共方法,将当前页码、GridView等作为参数传递。重点是在数据集填充时规定查询的数据条数。

当然前面要有相应的以Excel作为数据源的连接字符串及Open方法,这里不多说了。

 

相关文章:

  • 2022-01-11
  • 2021-12-10
  • 2021-11-18
  • 2021-06-21
  • 2021-05-29
猜你喜欢
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案