473,796 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exporting gridview to excel

I am using the following code to export my gridview to excel :

protected void btnExport_Click (object sender, ImageClickEvent Args e)
{
Response.Clear( );
Response.AddHea der("content-disposition",
"attachment;fil ename=FileName. xls");

Response.Charse t = "";

// If you want the option to open the Excel file without saving
than

// comment out the line below

// Response.Cache. SetCacheability (HttpCacheabili ty.NoCache);

Response.Conten tType = "applicatio n/vnd.ms-excel";

System.IO.Strin gWriter stringWrite = new
System.IO.Strin gWriter();

System.Web.UI.H tmlTextWriter htmlWrite = new
HtmlTextWriter( stringWrite);

GridView1.Rende rControl(htmlWr ite);

Response.Write( stringWrite.ToS tring());

Response.End();
}

public override void VerifyRendering InServerForm(Co ntrol control)
{
// Confirms that an HtmlForm control is rendered for the
specified ASP.NET server control at run time.
}

My problem is that I am setting the text values of one of the columns in
the RowDataBound event, and doing so seems to mean that the text for
this column is not exported, whereas if I don't set the text in the
RowDataBound event, the text is exported.

Here is my code for RowDataBound:

switch (Probability.Te xt)
{
case "0.25":
e.Row.Cells[4].Text = "A (25%)";
e.Row.Cells[4].BackColor =
System.Drawing. Color.PowderBlu e;
break;

case "0.5":
e.Row.Cells[4].Text = "B (50%)";
e.Row.Cells[4].BackColor =
System.Drawing. Color.DeepSkyBl ue;
break;

Can anybody help with this?

*** Sent via Developersdex http://www.developersdex.com ***
Jun 8 '06 #1
0 1358

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

Similar topics

2
3648
by: manmit.walia | last post by:
Hello Fellow Developers, I have a small problem that you might be able to help me with. The method that I am trying to create is the ability to export a GridView and a image to word or excel. I know that some people have already post about this topic but could not find a reliable answer. To my knowledge, I have the code down right. The GridView writes to the word document perfectly just not the image. All I get is a red 'x' image...
0
1537
by: ChrisN | last post by:
My app displays a dataset in a GridView and also exports it to Excel. Characters with diacritical marks (eg umlaut) show up just fine in the GridView but are mangled when exported to Excel. Eg HKS Fördertechnik AG becomes
4
2520
by: Tom | last post by:
I have a gridview on all of my web pages in my web app and they all export to excel. I have one page where the gridview is binding to a datatable that i created and only the first column is exporting to excel. How can I get the entire grid to export to excel?
0
1275
by: gujarsachin2001 | last post by:
Hi Friends, I am expeorting data from gridview to excel data is exporting fine .But saving file or cancling saving file when I am coming back to my web page it gets hanged ......... So can any body please help me out. Thanks, Sachin.
0
1798
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...
2
1329
by: austboss | last post by:
I have an aspx page that retrieves data from several different sources and uses them to define a new GridView, which is the exported as an Excel file. I originally had all of the code required in a single Page_Load sub. Once I worked out all of the standard problems that seem to trouble those of us trying to export to Excel, it was working fine. But now I need to make it so that it exports exports the GridView as an Excel file upon clicking...
1
3403
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...
2
4228
by: ASF | last post by:
Hey all, I have a gridview with an objectdatasource. I've been using the below code to export to excel: gvITV.AllowSorting = False gvITV.DataBind() Dim tw As New IO.StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) Dim frm As HtmlForm = New HtmlForm() Response.ContentType = "application/vnd.ms-excel"
1
208
by: Andrew Cooper | last post by:
I've got an ASP.NET page with a GridView connected to an Object Data Source. The GridView is working fine but my users would like the information to also be available in an Excel spreadsheet format. Is there any way to export the data from either the Data Source or from the Grid View into an Excel document programmatically and then link to it? Andrew Cooper
0
9531
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
10459
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
10237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10018
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...
1
7553
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
6795
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
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
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
2928
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.