Export GridView to Excel fails due to large dataset. Any suggestions?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Howdy. Ive done my first C# Web project and Im having an issue exporting out my gridview to excel when the grid has a large amount of data (11K rows is what my count shows). When I click the export button, I see the status bar of the browser
issue an Update (1%) and then the browser displays a "connection was reset" message. I do not get this message when the gridview has a reasonable amount of records and the export to Excel works as expected.
Any suggestions?
Thank you
Heres the export code:
<pre class="prettyprint protected void Page_Load(object sender, EventArgs e)
{
this.ConnectionString = ConfigurationManager.ConnectionStrings["DDW"].ConnectionString;
if (!Page.IsPostBack) //only populate listbox on first visit
{
//this passes connection to the constructor in class
oCustomerVoids = new TeraDataServices.CustomerVoids(this.ConnectionString);
lstAppl.DataSource = oCustomerVoids.GetApplID();
BindData(lstAppl);


//Add Data to cancel reason list
lstCancelReason.DataSource = oCustomerVoids.GetCancelReasons();
BindData(lstCancelReason);
}

}


protected void btnExcelExport_Click(object sender, EventArgs e)
{
string attachment = "attachment; filename=CustomerVoids.xls";

Response.Buffer = true;
Response.Charset = "";

Response.ClearContent();

Response.AddHeader("content-disposition", attachment);

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; //"application/vnd.ms-excel";

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);

// Create a form to contain the grid

HtmlForm frm = new HtmlForm();

GridView1.Parent.Controls.Add(frm);

frm.Attributes["runat"] = "server";

frm.Controls.Add(GridView1);

frm.RenderControl(htw);



//GridView1.RenderControl(htw);

Response.Write(sw.ToString());

Response.End();

}[/code]
<br/>

<br/>

View the full article
 
Back
Top