473,804 Members | 3,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bug when I export the contents of a GridView control to an Excel f

I experienced a bug, "Control GridView1 of type GridView myst be placed
inside a form tag with runat=server". But I did so. I do not why, please
advise. my code as below. Thanks.
Peter
<%@ Page language="C#" %>
<script runat="server">
protected void Page_Load(objec t sender, EventArgs e)
{
// Response.Write( "");
TheLabel.Text = " ";
}

void doExport(object sender, EventArgs e) {

string connectionStrin g
= "server=myServe r;database=myDa tabase;uid=John Doe;pwd=xyz";
System.Data.Sql Client.SqlConne ction con
= new System.Data.Sql Client.SqlConne ction(connectio nString);
using (con)
{
con.Open();
TheLabel.Text = "<b>table tblGeoMA</b> ";
string sql = "select * from tblGeoMA";
System.Data.Sql Client.SqlDataA dapter da
= new System.Data.Sql Client.SqlDataA dapter(sql, con);

System.Data.Dat aSet ds = new System.Data.Dat aSet();
da.Fill(ds,"dsT able1");

GridView1.DataS ource = ds;
GridView1.DataM ember = "dsTable1";
TheLabel.Text = " export the data in GridView to excel ";
Response.Clear( );
Response.AddHea der("content-disposition",
"attachment;fil ename=peter1.xl s");
Response.Charse t = "";
Response.Cache. SetCacheability (HttpCacheabili ty.NoCache);
Response.Conten tType = "applicatio n/vnd.xls";
System.IO.Strin gWriter stringWrite = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter htmlWrite
= new System.Web.UI.H tmlTextWriter(s tringWrite);
GridView1.DataB ind();
GridView1.Rende rControl(htmlWr ite);
//Response.Write( stringWrite.ToS tring());
Response.Write( "hello");
Response.End();
}
}
</script>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView 2Excel - test 5</title>
</head>
<body>
<form id="form1" runat="server">
<asp:button runat="server" text="export to excel" onclick="doExpo rt"
/><br />
<asp:label runat="server" text="" id="TheLabel" />
<asp:GridView runat="server" id="GridView1" />
</form>
</body>
</html>

May 16 '06 #1
0 1249

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

Similar topics

1
4526
by: Rob | last post by:
I was looking for the easiest way to take a datagrid full of data including two template columns, and export the contents of the grid into Excel by giving an "open or save as" box. I came across the following control which I thought might do it: http://www.codeproject.com/aspnet/Excel_CSV_export_button.asp However, I'm not sure if I added the control correctly to my project via VS2003 or if I am handling the Datagrid to what appears...
3
4108
by: Seagull Ng | last post by:
Hello all, I am doing my web-based reporting tool in ASP.Net 2.0 using Visual Web Developer 2005. I try to export my populated gridview to Excel spreadsheet but what I got is just a blank spreadsheet with only <div></div> tag in the first cell. Can anyone tell me what actually is the problem? Thanks in advance.
11
5652
by: Not Me | last post by:
Hi, I'm trying to export from a gridview control, to an excel file using code intended for a datagrid control (it's all over the web, can post if requested) I get the error. Control 'gvSearch' of type 'GridView' must be placed inside a form tag with runat=server.
5
2825
by: karthick | last post by:
Hi, I am exporting a Gridview to Excel and it works fine without any issues. But as one of the field holds values such as "71646E100" it gets converted to: "7.16E+104" (like a formula) in Excel. How can I prevent this from happening ?. I need to value to be in Excel as it is displayed in the Gridview (on the web page).
0
1800
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
6489
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
3364
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...
0
1560
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.
0
1927
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
9706
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...
0
9579
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,...
0
10577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10077
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
6853
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
5521
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...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
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
3
2991
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.