473,385 Members | 1,606 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,385 software developers and data experts.

exporting gridview to excel

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

protected void btnExport_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");

Response.Charset = "";

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

// comment out the line below

// Response.Cache.SetCacheability(HttpCacheability.No Cache);

Response.ContentType = "application/vnd.ms-excel";

System.IO.StringWriter stringWrite = new
System.IO.StringWriter();

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

GridView1.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();
}

public override void VerifyRenderingInServerForm(Control 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.Text)
{
case "0.25":
e.Row.Cells[4].Text = "A (25%)";
e.Row.Cells[4].BackColor =
System.Drawing.Color.PowderBlue;
break;

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

Can anybody help with this?

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

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

Similar topics

2
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...
0
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 ...
4
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...
0
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...
0
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...
2
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...
1
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...
2
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.