zimmer9
asked on
How to avoid an error (XML page cannot be displayed) when exporting GridView records to an Excel file using ASP.Net 4.0 with VS 2010 in C#?
I am creating my first ASP.NET web application.
I try to export a GridView to Excel using the following code but I get the following error once I click on the command button:
-------------------------- ---------- ---------- --
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
The operation completed successfully. Error processing resource 'http://localhost:4380/default.aspx'. Line 6, Position 95
<td>5455</td><td>10/3/2013 </td><td>1 0/3/2013</ td><td>New Rejects from current d...
-------------------------- ---------- ---------- ---------- ----
The C# code for my command button to Export the GridView records to Excel is as follows:
protected void Button1_Click1(object sender, EventArgs e)
{
Response.ClearContent();
Response.AppendHeader("con tenet-disp osition", "attachment; filename-Clients.xls");
Response.ContentType = "application/excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWrite r);
GridView1.RenderControl(ht mlTextWrit er);
Response.Write(stringWrite r.ToString ());
Response.End();
}
public override void VerifyRenderingInServerFor m(Control control)
{
}
I try to export a GridView to Excel using the following code but I get the following error once I click on the command button:
--------------------------
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------
The operation completed successfully. Error processing resource 'http://localhost:4380/default.aspx'. Line 6, Position 95
<td>5455</td><td>10/3/2013
--------------------------
The C# code for my command button to Export the GridView records to Excel is as follows:
protected void Button1_Click1(object sender, EventArgs e)
{
Response.ClearContent();
Response.AppendHeader("con
Response.ContentType = "application/excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWrite
GridView1.RenderControl(ht
Response.Write(stringWrite
Response.End();
}
public override void VerifyRenderingInServerFor
{
}
the error is in your XSL style sheet, check that for correct mapping
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.