Click here to Skip to main content
15,567,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to download gridview data to excel but i am getting error like this [System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

here is code ..please tell me anyone
C#
string filename = "DownloadMobileNoExcel.xls";
                                System.IO.StringWriter tw = new System.IO.StringWriter();
                                System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
                                GridExcelDetails.DataSource = GetTSubscriberDetails;
                                GridExcelDetails.DataBind();
                                updatexcel.Update();
                                //Get the HTML for the control.
                                GridExcelDetails.RenderControl(hw);
                                //Write the HTML back to the browser.
                                //Response.ContentType = application/vnd.ms-excel;
                                Response.ContentType = "application/vnd.ms-excel";
                                Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
                                this.EnableViewState = false;
                                Response.Write(tw.ToString());                                
                                Response.End();



C#
public override void VerifyRenderingInServerForm(Control control)
        {

        }
Posted
Updated 11-Dec-12 3:32am
v2
Comments
Tioned 4-Apr-16 8:23am    

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