日期:2014-05-18  浏览次数:20431 次

GridView的导出excel问题,请高手帮忙
public void ExporExcelFile()
  {
  Response.Clear();
  Response.AddHeader("content-disposition", "attachment;filename=ExcelFile.xls");
  Response.Charset = "gb2312";
  Response.ContentType = "application/ms.xls";
  System.IO.StringWriter stringWrite = new System.IO.StringWriter();
  System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
  GridView.AllowPaging = false;
  GridView.AllowSorting = false;
  GridView.DataBind();
  GridView.RenderControl(htmlWrite);
  Response.Write(stringWrite.ToString());
  Response.End();
  GridView.AllowPaging = true;
  GridView.AllowSorting = true;
  GridView.DataBind();
  }
  public override void VerifyRenderingInServerForm(Control control)
  {
   
  }
这个导出程序,怎么导出的内容只有两个<div>,并没有gridview中的内容呢。

------解决方案--------------------
GridView.DataSource=???

你没绑定数据源啊,怎么会有内容?
------解决方案--------------------
GridView.DataBind();

绑定写了2次,就是木写绑定数据源
------解决方案--------------------
探讨
public void ExporExcelFile()
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ExcelFile.xls");
Response.Charset = "gb2312";
Response.ContentType = "app……

------解决方案--------------------
没有绑定数据源
GridView1.DataSource=??
GridView1.DataBind()