DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 5 Jun 2007 07:29:20 +0700,    posted on: microsoft.public.dotnet.framework.aspnet.datagridcontrol        back       

Thread Index
  1    Gunawan
          2    MasterGaurav \(www.edujini-labs.com\)
                 3    Gunawan
                        4    MasterGaurav \(www.edujini-labs.com\)
                 5    Gunawan
                 6    MasterGaurav \(www.edujini-labs.com\)
                        7    Gunawan
                               8    MasterGaurav \(www.edujini-labs.com\)


GridView issue when export to excel   
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
Date:Tue, 5 Jun 2007 07:29:20 +0700   Author:  

Re: GridView issue when export to excel   

>        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
-----------------------------------------
Date:Tue, 5 Jun 2007 18:36:20 +0530   Author:  

Re: GridView issue when export to excel   
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:uU64aJ3pHHA.4196@TK2MSFTNGP06.phx.gbl...

>>        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
> -----------------------------------------
>
> 
Date:Wed, 6 Jun 2007 11:09:43 +0700   Author:  

Re: GridView issue when export to excel   

> 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
-----------------------------------------
Date:Wed, 6 Jun 2007 10:12:00 +0530   Author:  

Re: GridView issue when export to excel   
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$pHHA.4120@TK2MSFTNGP06.phx.gbl...

>> 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
> ----------------------------------------- 
>
> 
Date:Thu, 7 Jun 2007 15:23:44 +0700   Author:  

Re: GridView issue when export to excel   

>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
-----------------------------------------
Date:Sun, 10 Jun 2007 22:20:42 +0530   Author:  

Re: GridView issue when export to excel   
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%233qHHA.4180@TK2MSFTNGP04.phx.gbl...

> >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
> -----------------------------------------
>
> 
Date:Mon, 11 Jun 2007 11:35:44 +0700   Author:  

Re: GridView issue when export to excel   
Ah! Forgot about it :)


ok.... I have a code that looks something liks this:

 protected void LinkButton1_Click(object sender, EventArgs e)
 {
  Response.ClearHeaders();
  Response.Clear();

  Response.Charset = "";
  Response.ContentType = "application/vnd.ms-excel";
  Response.AddHeader("Content-Disposition", "attachment; 
filename=Customers.xls");

  StringWriter strWriter = new StringWriter();
  HtmlTextWriter hwriter = new HtmlTextWriter(strWriter);
  GridView1.RenderControl(hwriter);
  Response.Write(strWriter.ToString());
  Response.End();

 }


 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"  wrote in message 
news:etai2H%23qHHA.3456@TK2MSFTNGP02.phx.gbl...

>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%233qHHA.4180@TK2MSFTNGP04.phx.gbl...
>> >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
>> -----------------------------------------
>>
>>
>
> 
Date:Wed, 13 Jun 2007 22:26:00 +0530   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us