如题.
我要先将查询出来的数据显示在Gridview控件中,然后导出为EXCEL文件.
查询出来的每一笔数据的字段不一样,我应该怎样实现上面的功能,谢谢!!!

解决方案 »

  1.   

    public static void GenerateByGridView(string Typename, GridView TempGrid)
            {
                HttpContext.Current.Response.Clear();
                //HttpContext.Current.Response.Buffer = true;
                HttpContext.Current.Response.Charset = "utf-8";
                string Filename = Typename + ".xls";
                HttpContext.Current.Response.AppendHeader("Content-Disposition", "online;filename=" + Filename);
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
                HttpContext.Current.Response.ContentType = "application/ms-excel";
                //this.EnableViewState = false;
                System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
                TempGrid.RenderControl(oHtmlTextWriter);
                HttpContext.Current.Response.Write(oStringWriter.ToString());
                HttpContext.Current.Response.End();
            }Typename 为文件名
      

  2.   

    请参考这篇文章:
    http://dotnet.aspx.cc/article/700bd3fa-a17f-41dc-b258-0dc572625700/read.aspx
      

  3.   

    我试了glacier111(★冰河★)给出来的代码,但运行时有如下错误,不知道什么原因,还请各位大虾赐教!错误  No overload for 'btn_output_Click' matches delegate 'System.EventHandler'