473,659 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Http Exception 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.C ontrolCollectio n.Add(Control child)
at datawarehouse.i ndividual._defa ult.ClearContro ls(Control control) in
c:\Inetpub\wwwr oot\datawarehou se\individual\d efault.aspx.cs: line 131
at datawarehouse.i ndividual._defa ult.ClearContro ls(Control control) in
c:\Inetpub\wwwr oot\datawarehou se\individual\d efault.aspx.cs: line 123
at datawarehouse.i ndividual._defa ult.excelExport (Object sender,
ImageClickEvent Args e) in
c:\Inetpub\wwwr oot\datawarehou se\individual\d efault.aspx.cs: line 173
at System.Web.UI.W ebControls.Imag eButton.OnClick (ImageClickEven tArgs e)
at System.Web.UI.W ebControls.Imag eButton.RaisePo stBackEvent(Str ing
eventArgument)
at
System.Web.UI.W ebControls.Imag eButton.System. Web.UI.IPostBac kEventHandler.R aisePostBackEve nt(String
eventArgument)
at System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument)
at System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
at System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
------------------------------------------------------------------------------------------------

Code that I am using for export:

Code:

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

if (!(control is TableCell))
{
if (control.GetTyp e().GetProperty ("SelectedItem" ) !=
null)
{
LiteralControl literal = new LiteralControl( );
control.Parent. Controls.Add(li teral); //on this
line I am getting an error
try
{
literal.Text =
(string)control .GetType().GetP roperty("Select edItem").GetVal ue(control,
null);
}
catch
{
//error msg
}

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

else

if (control.GetTyp e().GetProperty ("Text") != null)
{
LiteralControl literal = new LiteralControl( );
control.Parent. Controls.Add(li teral);
literal.Text =
(string)control .GetType().GetP roperty("Text") .GetValue(contr ol, null);
control.Parent. Controls.Remove (control);
}
}
return;
}

public void excelExport(obj ect sender,
System.Web.UI.I mageClickEventA rgs e)
{
//export to excel
lblTitle.Text = "All individuals";

Response.Clear( );
Response.Buffer = true;
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.Charse t = "";
this.EnableView State = false;

System.IO.Strin gWriter oStringWriter = new
System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter oHtmlTextWriter = new
System.Web.UI.H tmlTextWriter(o StringWriter);

this.ClearContr ols(IndividualL ist1);
lblTitle.Render Control(oHtmlTe xtWriter);
IndividualList1 .RenderControl( oHtmlTextWriter );

Response.Write( oStringWriter.T oString());

Response.End();
}

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

Thanks is advance.

A.

Jan 18 '07 #1
0 1281

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

Similar topics

3
9237
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 only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
4
3942
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" TEXT field that contains data such as 2000/01, 2001/02, etc. If I export a Query with this kind of data to Excel, it gives me the text value of this field; however, when I export a Report bound to this TEXT field, Excel gives me the values 36526,...
2
7703
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
2402
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 exporting ALL data from the datagrid control. Exporting data works fine when I show all data on the datagrid control. I'd like to shows only 30 records on the datagrid control instead of ALL data using page navigation, and perform exporting...
21
6220
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 code use multiple excel tabs within a workbook???? Anyone have vba code that would create a temp table write 65,000 records to it, export those to excel, clean the temp table, append the next 65,000 records, export it to excel with a different...
2
3170
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 set this up so as to do it reliably and minimize overhead? There are currently no constraints on the destination table. Assume the user or some configuration specifies the database name, server name, and filename+fullpath. The server is SQL...
1
6972
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 works fine. But the problem is with the exported data. I am having values with leading zeros. for example: Patron Code
2
3575
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 works fine. But the problem is with the exported data. I am having values with leading zeros. for example: Patron Code
2
1807
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 records are exported successfully but this error pops up before the export is completed. When I run the debugger this line gives the error message(OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET) If Not (rsSchedules.EOF = True) Then Below is my...
3
2538
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. Ws.Range("A2").CopyFromRecordset rs One of my Field Name, DATATYPE is set to MEMO I am testing with DATATYPE As TEXT and the Characters within 255 then the report get's downloaded to Excel, if the DATATYPE is set to MEMO and the characters are more than 255 error...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.