GridView.DataBind()将大数据集导出到Excel时内存不足

时间:2013-05-24 16:10:21

标签: gridview asp.net-mvc-2 iis-6 windows-2003-webserver system.web.ui.webcontrols

我将“导出到Excel”按钮添加到我的jqGrid中。它工作正常,直到我将jqGrid链接到一个大型GridView,其中有20,000条记录,每条记录有200个字段(列)

我在DataBind()调用上得到了{“异常类型'System.OutOfMemoryException'。}}:

    public void ExportToExcel()
    {

        if (Session["query"] == null || Session["fieldNameAsDef"] == null)
        {
            return;
        }
        var grid = new GridView();
        List<string> fieldNameAsDef = (List<string>)Session["fieldNameAsDef"];
        grid.DataSource = ((IQueryable)Session["query"]).Select("new (" + string.Join(",", fieldNameAsDef.ToArray()) + ")");
        grid.DataBind();

        Response.ClearContent();
        Response.AddHeader("content-disposition", "attachment; filename=EDGE_ExcelFile.xls");
        Response.ContentType = "application/excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        grid.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }

System.Web.UI.WebControls.GridView的限制是什么? 或者是IIS 6和MVC2问题。

jqGrid及其作为DataSource的GridView是在Windows 2003 SP2服务器上运行的较旧的MVC 2应用程序的一部分,具有IIS 6和4 GB RAM。

0 个答案:

没有答案