GridView issue when export to excel

Discussion in 'ASP .Net Datagrid Control' started by Gunawan, Jun 5, 2007.

  1. Gunawan

    Gunawan Guest

    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
    Gunawan, Jun 5, 2007
    #1
    1. Advertising

  2. Gunawan

    Gunawan Guest

    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
    > -----------------------------------------
    >
    >
    Gunawan, Jun 6, 2007
    #2
    1. Advertising

  3. Gunawan

    Gunawan Guest

    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
    > -----------------------------------------
    >
    >
    Gunawan, Jun 7, 2007
    #3
  4. Gunawan

    Gunawan Guest

    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
    > -----------------------------------------
    >
    >
    Gunawan, Jun 11, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3JpZGhhcg==?=

    using Microsoft Excel image for Export to Excel button

    =?Utf-8?B?U3JpZGhhcg==?=, Dec 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,084
    =?Utf-8?B?U3JpZGhhcg==?=
    Dec 9, 2005
  2. Arvind R

    Export to Excel issue (C#)

    Arvind R, Jan 24, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    16,467
    =?Utf-8?B?YnJpYW5wbWNjdWxsb3VnaA==?=
    Feb 24, 2006
  3. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Export to Excel (Default File Type - Excel)

    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 24, 2006, in forum: ASP .Net
    Replies:
    15
    Views:
    17,474
    syed hassan
    May 21, 2009
  4. =?Utf-8?B?ZGlub28=?=

    Urgent - Asp.NET Datagrid export Excel - landscape Issue

    =?Utf-8?B?ZGlub28=?=, Aug 7, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    2,761
    =?Utf-8?B?ZGlub28=?=
    Aug 7, 2006
  5. Grey
    Replies:
    4
    Views:
    1,945
    Mark Rae [MVP]
    Oct 17, 2007
Loading...

Share This Page