Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 31st, 2006, 04:42 AM
Authorized User
 
Join Date: Mar 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem in exporting datagrid to excel

Hi all,

I am using the datagrid containing the template columns. I have the code for exporting datagrid to excel sheet. I also have the code for deleting the controls in the template column before exporting it to the datagrid. but I am still getting an error because I have bounded the template columns using databinder.eval

I want to export datagrid to excel sheet. will anybody help me in this matter.

 
Old May 31st, 2006, 08:42 AM
Authorized User
 
Join Date: Oct 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try the following and let me know if you have any problem


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

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);

this.ClearControls(compareTable);

compareTable.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

Software proffesional from Bangalore,INDIA
 
Old June 1st, 2006, 05:46 AM
Authorized User
 
Join Date: Mar 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

when I used the above code. I got following error

Server Error in '/schedule' Application.
--------------------------------------------------------------------------------

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.Add(Control child) +244
   schedule.timesheet.clearcontrols(Control control) +225
   schedule.timesheet.LinkButton1_Click(Object sender, EventArgs e) +203
   System.Web.UI.WebControls.LinkButton.OnClick(Event Args e) +108
   System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +138
   System.Web.UI.Page.ProcessRequestMain() +1263




 
Old June 4th, 2006, 11:26 PM
Authorized User
 
Join Date: Feb 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default


hi swati !!

just remove

Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.Cache.SetCacheability(HttpCacheability.No Cache);

this two statements

it will work
u can further mail me and ask anythign : [email protected]

bye










Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in exporting data from datagrid to Excel deb_kareng ASP.NET 2.0 Professional 4 August 4th, 2007 09:21 AM
exporting to excel from datagrid hotshot_21 ASP.NET 1.0 and 1.1 Basics 2 June 9th, 2006 08:53 AM
Exporting data to excel from datagrid, Problem. swadhinm ASP.NET 1.x and 2.0 Application Design 0 May 31st, 2005 01:44 AM
problem exporting datagrid to excel kscdave Classic ASP Professional 0 March 29th, 2005 11:57 AM
Exporting DataGrid To Excel chiefg C# 2 December 31st, 2003 12:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.