Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,
I want to export data in excel sheet which are display in gridview.
I put some code line but it give an error as follows:
Please help me for the same.
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
This is my Code block:
C#
try
{
           string attachment = "attachment; filename=Export.xls";
           Response.ClearContent();
           Response.AddHeader("content-disposition", attachment);
           Response.ContentType = "application/ms-excel";
           StringWriter sw = new StringWriter();
           HtmlTextWriter htw = new HtmlTextWriter(sw);
           HtmlForm frm = new HtmlForm();
           GRD_Final_Report.Parent.Controls.Add(frm);
           frm.Attributes["runat"] = "server";
           frm.Controls.Add(GRD_Final_Report);
           frm.RenderControl(htw);
           Response.Write(sw.ToString());
           Response.End();
}
Catch(Exception ex)
{
}
Posted
Updated 8-Apr-15 19:14pm
v2
Comments
BulletVictim 9-Apr-15 2:16am    
Try looking at this http://www.codeproject.com/Tips/477436/Export-Gridview-Data-to-Excel-in-ASP-NET
What it basically does is, it takes the data of the gridview, places it in a dataset and then from there exports the dataset to excel.

For possible misunderstanding the question. Here is exapmles of where the excel file's data is displayed in a gridview.
http://stackoverflow.com/questions/7315782/display-excel-file-content-in-a-datagridview
and
http://stackoverflow.com/questions/17568604/import-excel-data-to-datagridview-in-visual-studio-2010.

Hope this helps
Maciej Los 9-Apr-15 2:26am    
Is it ASP.NET?

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900