Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > GridView issue when export to excel

Reply
Thread Tools

GridView issue when export to excel

 
 
Gunawan
Guest
Posts: n/a
 
      06-05-2007
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.No Cache);

Response.Cache.SetCacheability(HttpCacheability.No Cache);
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




 
Reply With Quote
 
 
 
 
Gunawan
Guest
Posts: n/a
 
      06-06-2007
Thank you for your reply

change to this
>> gv.RenderControl(htmlWrite);
>> //this.RenderControl(htmlWrite);


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?


"MasterGaurav (www.edujini-labs.com)" <>
wrote in message news:...
>> System.IO.StringWriter stringWrite = new System.IO.StringWriter();
>> System.Web.UI.HtmlTextWriter htmlWrite =
>> new HtmlTextWriter(stringWrite);
>>
>> //gv.RenderControl(htmlWrite);
>> this.RenderControl(htmlWrite);

>
> It should not be this.RenderControl but gridView.RenderControl(htmlWrite)
>
> It's the GridView that has to be rendered and not the page (this)!!!
>
> --
> Happy Hacking,
> Gaurav Vaish | www.mastergaurav.com
> www.edujini-labs.com
> http://eduzine.edujini-labs.com
> -----------------------------------------
>
>



 
Reply With Quote
 
 
 
 
Gunawan
Guest
Posts: n/a
 
      06-07-2007
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."


"MasterGaurav (www.edujini-labs.com)" <>
wrote in message news:%23PCTRU$...
>> I have this error when rendering GridView
>> "Control 'gv' of type 'GridView' must be placed inside a form tag with
>> runat=server."

>
> Ensure that you override the method "VerifyRenderingInServerForm" with no
> code:
>
> public override void VerifyRenderingInServerForm(Control control)
>
> {
>
> //don't throw any exception!
>
> }
>
>
>
> --
> Happy Hacking,
> Gaurav Vaish | www.mastergaurav.com
> www.edujini-labs.com
> http://eduzine.edujini-labs.com
> -----------------------------------------
>
>



 
Reply With Quote
 
Gunawan
Guest
Posts: n/a
 
      06-11-2007
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

"MasterGaurav (www.edujini-labs.com)" <>
wrote in message news:ecItI%...
> >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."

>
>
> Can you put up the entire code for download somewhere?
>
> --
> Happy Hacking,
> Gaurav Vaish | www.mastergaurav.com
> www.edujini-labs.com
> http://eduzine.edujini-labs.com
> -----------------------------------------
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to Excel (Default File Type - Excel) =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?= ASP .Net 15 05-21-2009 12:01 PM
Export to excel in asp.net using excel template Grey ASP .Net 4 10-17-2007 08:08 AM
bug when I export the contents of a GridView control to an Excel f =?Utf-8?B?UGV0ZXI=?= ASP .Net 0 05-16-2006 01:11 PM
Export datalist or gridview to Excel staeri@gmail.com ASP .Net 2 03-07-2006 08:19 PM
using Microsoft Excel image for Export to Excel button =?Utf-8?B?U3JpZGhhcg==?= ASP .Net 0 12-09-2005 08:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57