473,503 Members | 1,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hiding columns upon download from gridview to excel

I have a gridview that has six columns. I need to hide the last column
(i.e. not download it) in the download from gridview to excel. My
current code (which downloads the entire gridview) is as follows:

public static void ExportExcelFile(Control htmlData, string
filename)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename="
+ filename + ".xls");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/
vnd.xls";
System.IO.StringWriter stringWrite = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
htmlData.RenderControl(htmlWrite);
HttpContext.Current.Response.Write(stringWrite.ToS tring());
HttpContext.Current.Response.End();
}

I am calling this by the following code:

protected void btnDownloadDebit_Click(object sender, EventArgs e)
{
grvDebit.Columns[5].Visible = false;
Util.ExportExcelFile(grvDebit, "DebitDetail");
grvDebit.Columns[5].Visible = true;

}

I thought that making the fifth column's visible property to false
before the call would result in that column not being downloaded. I
was wrong. Can anyone give me some advice on this? Thanks for all help
in advance.

Dave
Mar 26 '08 #1
0 1245

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

Similar topics

5
7556
by: Morten Mikkelsen | last post by:
Hi, On my SQL Server 2000, I have a table of data (tblAllData) containing a number of columns, some of which are 'secret'. I have to let some users access the database using ODBC from an Excel...
5
1618
by: srinivas | last post by:
Hi, I have binded a dataset to a gridview control at run time. I'm fetching 5 columns from the database. But while displaying it on the screen i want to show only 3 columns. I tried with...
0
1005
by: CSharpguy | last post by:
Ok, i got my gridview (sortable and non sorting) to export to excel. BUt now 3 of my gridviews I have a as:TemplateField which are links. So how can I hide those 3 columns when I export the...
2
1630
by: =?Utf-8?B?Sm9zaCBTY2htaWR0?= | last post by:
I have a gridview that is being used for managing inventory. The default view shows the stock currently available. When editing I don't want the stock to be directly edited, rather the user will...
1
1799
by: Dica | last post by:
i need to allow the user to select a row from my dataGrid for editing. as such, i include the record ID in the first column and then extract like so when retrieving the record details: protected...
2
2889
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
Based on wether a row is selected in a GridView I need to HIDE the last two columns of a gridview. I do NOT need to make the cells invisible I want to hide the entire column. When I set the...
9
2880
by: RobertTheProgrammer | last post by:
Hi all, Hopefully this one is rather simple. I just haven't been able to figure it out. On my GridView I have some hidden key columns which I've hidden by using tha attribute Visible="false"...
6
18545
by: vinod allapu | last post by:
Hi boss, I have a gridview, bound to a datasource . Here i want to add columns dynamically containing empty textboxes. Number of columns are variant . The added columns are not bound to...
9
12025
by: ally | last post by:
Hi, I am programmatically binding gridview to a datatable. I want to hide 2 columns. I can be done by adding code in RowCreated event of gridview like e.Row.Cells.Visible = false; ...
0
7063
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...
0
7258
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,...
0
7313
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...
1
6970
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...
1
4987
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...
0
3156
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...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
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 ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.