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. Advertisements

  2. Gunawan

    Gunawan Guest

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

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

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 (here). After that, you can post your question and our members will help you out.