473,657 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP NET 2.0 - GridView export to EXCEL HELP

74 New Member
Hi,

Hi someone can help me on this?

Currently I have a Listdata.aspx page with datagrid, I wish to export my datagrid content to excel with following code ( with button export click event):-

But when I run the code, it raise an error
-> Control 'ctl02_GridView 1' of type 'GridView' must be placed inside a form tag with runat=server"

My Listdata.aspx page are place under MasterPage.aspx , which is inside Contentplace holder. how to solve this? I can't put my GridView1 in Master page, cause Listdata.aspx are inside contentplace holder of Master page. Please help

protected void btnExport_Click (object sender, EventArgs e)
{
PrepareGridView ForExport(GridV iew1);
ExportTerminati onLog();
}

private void PrepareGridView ForExport(Contr ol gv)
{
LinkButton lb = new LinkButton();
Literal l = new Literal();

string name = String.Empty;

for (int i = 0; i < gv.Controls.Cou nt; i++)
{

if (gv.Controls[i].GetType() == typeof(LinkButt on))
{

l.Text = (gv.Controls[i] as LinkButton).Tex t;

gv.Controls.Rem ove(gv.Controls[i]);

gv.Controls.Add At(i, l);

}

else if (gv.Controls[i].GetType() == typeof(DropDown List))
{

l.Text = (gv.Controls[i] as DropDownList).S electedItem.Tex t;

gv.Controls.Rem ove(gv.Controls[i]);

gv.Controls.Add At(i, l);

}

else if (gv.Controls[i].GetType() == typeof(CheckBox ))
{

l.Text = (gv.Controls[i] as CheckBox).Check ed ? "True" : "False";

gv.Controls.Rem ove(gv.Controls[i]);

gv.Controls.Add At(i, l);

}

if (gv.Controls[i].HasControls())
{
PrepareGridView ForExport(gv.Co ntrols[i]);
}
}
}


private void ExportTerminati onLog()
{

string attachment = "attachment ; filename=Termin ation.xls";
Response.ClearC ontent();
Response.AddHea der("content-disposition", attachment);
Response.Conten tType = "applicatio n/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter( sw);
GridView1.Rende rControl(htw);
Response.Write( sw.ToString());
Response.End();
}
Jun 13 '07 #1
0 2566

Sign in to post your reply or Sign up for a free account.

Similar topics

3
10112
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type GridView must be placed inside form tag with runat = server". I understand that this is because my Masterpage has the formtag and not the eventslisting page. As a workaround I programatically created an HTML form, added runat=server attribute to it...
0
1785
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a gridview. I calculated some values in the gridview for the footer of the gridview so basically I am adding all the values that are displayed in the gridview for each column and displaying the total in the footer of the gridview. Now I export the gridview to excel spreadsheet with the code below. Everything is exported well except the footer value become zero in the excel spreadsheet. Can anyone tell me how can i...
6
6476
by: Sergio E. | last post by:
Hi, I'm looking for information about gridview's cell properties... I've the following case: one gridview with alternatirg row style and normalrowstyle, 3 o 4 custom styles that are applied to cells in the row_databound event, and now I nedd to do a excel export of the gridview exactly as is showed in the browser, but al the examples and thigs I've tried don't send the cell color to excel and now I think if I can read the gridview...
1
3362
by: edwinparker | last post by:
Hi, I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The problem is, the image won't display unless I'm connected to the Internet or if I use a relative path and have the image stored relative to the excel file. Is it possible to "embed" the image from the gridview into the excel workbook so I could give...
2
3929
by: =?Utf-8?B?SkRSYXZlbg==?= | last post by:
I have searched all over and can not seem to find an effective way to simply copy the contents of a ASP:gridview column to the clipboard based on a button or similar HTML or ASP.NET control. ASP 2.0 web application with VB.NET code developing in Visual Studio 2005 Pro. Gridview has several columns, and users need the ability to copy one of the columns to the clipboard for pasting into a separate app (that already has the ability to...
1
3389
by: Yordan Georgiev | last post by:
I have a search form using master page , which is dynamically generated from the column names of the database - when the users have a search result it should be exported to Excel by clicking the button ... I get the following message : A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in...
0
1551
by: =?Utf-8?B?U2hhbQ==?= | last post by:
Hai all, In my application, I need to Export webpage things into hard drive. I am using gridview, and i export all things(with the help of some sites) into excel except images. Please, Can any one tell me how to export all contents of(Including Images) gridview into excel.
3
5202
by: ulai | last post by:
Thanks for your help. It really help to solve my work. But now i have a bigger problem : I had more than 65535 records in gridview divide by 10/pages. And when i tried to export the gridview in excel on every way : 1. I disabled the allowpaging in gridview and got and error messages like : System.OutOfMemoryException Was Thrown 2. My idea is to store row in gridview to virtable per pages. I create virtable as Table. Added row to virtable...
0
1915
by: hiranmaie | last post by:
Hi, I have a gridview with more than 10 rows of data. I want to export these gridview values into an excel sheet along with the header names of excel sheet. I am not using a database here. I need to open an excel application at the click of a button and save the gridview values into the excel sheet opened. Please help me out to solve this problem. Thanks & Regards,
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8513
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
8613
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
7351
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
6176
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
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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
2740
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
1732
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.