日期:2014-05-17  浏览次数:20419 次

Excel里面内容太大 导入到gridview中 Internet页面无法显示
Excel里面内容太大 导入到gridview中 Internet页面无法显示 求帮忙修改下
后台代码如下:
  protected void Button1_Click(object sender, EventArgs e)
  {
  string type1 = FileUpload1.PostedFile.ContentType;
  string type = type1.Substring(type1.LastIndexOf("-") + 1 , 5);

  if (string.Equals(type, "excel"))
  {
  string newName = Server.MapPath("App_Data//") + DateTime.Now.ToString("hhmmss") + ".xls";
  FileUpload1.SaveAs(newName);//上传到服务器
  string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + newName + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1;'";
  OleDbConnection conn = new OleDbConnection(connStr);
  if (conn.State.ToString() == "Closed")
  {
  conn.Open();
  }
  OleDbDataAdapter oda = new OleDbDataAdapter("select * from [Sheet1$]", conn);
  DataSet ds = new DataSet();
  oda.Fill(ds);
  conn.Close();
  GridView1.DataSource = ds;
  GridView1.DataBind();
  File.Delete(newName);
  Session["USER"] = ds;
  Button3.Visible = true;

  }
  else
  {
  Page.RegisterStartupScript("", "<script>alert('文件格式不正确')</script>");
  }
  }

------解决方案--------------------
分页显示
------解决方案--------------------
分页显示啊,帅哥。
------解决方案--------------------
数据量大的话,尽量分页。
------解决方案--------------------
列的问题你可以放在表格里面,然后动用滚动条,不然你还想怎么样?
不然就分批显示咯,在末端放个“更多”按钮让用户点。