473,228 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

error in exporting data into excel

Hello,

I am trying to export data to excel from datagrid, and I am getting an
error: "The Controls collection cannot be modified because the control
contains code blocks (i.e. <% ... %>)."

Error details:
System.Web.HttpException was unhandled by user code
Message="The Controls collection cannot be modified because the control
contains code blocks (i.e. <% ... %>)."
Source="System.Web"
ErrorCode=-2147467259
StackTrace:
at System.Web.UI.ControlCollection.Add(Control child)
at datawarehouse.individual._default.ClearControls(Co ntrol control) in
c:\Inetpub\wwwroot\datawarehouse\individual\defaul t.aspx.cs:line 131
at datawarehouse.individual._default.ClearControls(Co ntrol control) in
c:\Inetpub\wwwroot\datawarehouse\individual\defaul t.aspx.cs:line 123
at datawarehouse.individual._default.excelExport(Obje ct sender,
ImageClickEventArgs e) in
c:\Inetpub\wwwroot\datawarehouse\individual\defaul t.aspx.cs:line 173
at System.Web.UI.WebControls.ImageButton.OnClick(Imag eClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBac kEvent(String
eventArgument)
at
System.Web.UI.WebControls.ImageButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
------------------------------------------------------------------------------------------------

Code that I am using for export:

Code:

private void ClearControls(Control control)
{
for (int i = control.Controls.Count - 1; i >= 0; i--)
{
ClearControls(control.Controls[i]);
}

if (!(control is TableCell))
{
if (control.GetType().GetProperty("SelectedItem") !=
null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal); //on this
line I am getting an error
try
{
literal.Text =
(string)control.GetType().GetProperty("SelectedIte m").GetValue(control,
null);
}
catch
{
//error msg
}

control.Parent.Controls.Remove(control);
}

else

if (control.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
literal.Text =
(string)control.GetType().GetProperty("Text").GetV alue(control, null);
control.Parent.Controls.Remove(control);
}
}
return;
}

public void excelExport(object sender,
System.Web.UI.ImageClickEventArgs e)
{
//export to excel
lblTitle.Text = "All individuals";

Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);

this.ClearControls(IndividualList1);
lblTitle.RenderControl(oHtmlTextWriter);
IndividualList1.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();
}

Maybe have anybody ideas how to solve this problem and fix this error.

Thanks is advance.

A.

Jan 18 '07 #1
0 1256

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
4
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear"...
2
by: G | last post by:
When I export data from access to excel by with "export" or "Analyze with" I seem to loose parts of some fields (long text strings). Is there a way to export it all to excel? Thanks G
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
21
by: bobh | last post by:
Hi All, In Access97 I have a table that's greater than 65k records and I'm looking for a VBA way to export the records to Excel. Anyone have vba code to export from access to excel and have the...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
1
by: 333sridhar333 | last post by:
Hi, I am having a problem in exporting a data from jsp to excel. I am getting the values from a servlet and populating it to a JSP. And form there i export them to Excel. The functionality...
2
by: 333sridhar333 | last post by:
Hi, I am having a problem in exporting a data from jsp to excel. I am getting the values from a servlet and populating it to a JSP. And form there i export them to Excel. The functionality...
2
by: accessvbanewbie | last post by:
I keep getting an error stating OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET. This error just recently began to happen. I am exporting some records to excel into a preformatted report. The...
3
by: Tempalli | last post by:
I am exporting the data from ms access to excel where the error displays as Run-time error -2147467259(800004005) Method 'Copyfromrecordset' of object 'Range' faild. ...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.