GridView issue when export to excel

G

Gunawan

Hi there,
I am using this code that I have found in the internet to generate excel
output.

Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=kirim.xls");
Response.Charset = "";

// If you want the option to open the Excel file without saving than
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);

//gv.RenderControl(htmlWrite);
this.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());
Response.End();


But I've got this error (Exception) bellow when Response.End() issue.
"Unable to evaluate expression because the code is optimized or a native
frame is on top of the call stack."

How to correct this issue?

Regards,
Gun
 
G

Gunawan

Thank you for your reply

change to this
I have this error when rendering GridView
"Control 'gv' of type 'GridView' must be placed inside a form tag with
runat=server."


<form id="frmRencanaKirim" runat="server">
<div>
<asp:GridView ID="gv" runat="server"
AutoGenerateColumns="False"
ForeColor="#333333"
CellPadding="2"
AllowPaging="false"
ShowFooter="True">
<HeaderStyle BackColor="#507CD1"
Font-Bold="True" ForeColor="White"/>
<FooterStyle BackColor="#507CD1"
Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" Height="25px" />
<AlternatingRowStyle BackColor="White" />
<Columns>
...
</Columns>
</asp:GridView>
<asp:Label ID="lbMessage" runat="server" Text=" "
ForeColor="Red" Visible="False" />
</div>
</form>


What's wrong?
 
G

Gunawan

I have tried follow your suggestion...

After all, it back to original issue.

"Unable to evaluate expression because the code is optimized or a native
frame is on top of the call stack."
 
G

Gunawan

I have, didn't I? On my first post.

Error occurred when issue Response.End();
No matter what data that I would like to show in gridview.
Regards,
Gun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,708
Messages
2,569,346
Members
44,650
Latest member
LuckyVivo

Latest Threads

Top