473,780 Members | 2,258 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.Cur rent.Response.C lear();
HttpContext.Cur rent.Response.A ddHeader("conte nt-disposition",
"attachment;fil ename="
+ filename + ".xls");
HttpContext.Cur rent.Response.C harset = "";
HttpContext.Cur rent.Response.C ontentType = "applicatio n/
vnd.xls";
System.IO.Strin gWriter stringWrite = new
System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter htmlWrite = new
HtmlTextWriter( stringWrite);
htmlData.Render Control(htmlWri te);
HttpContext.Cur rent.Response.W rite(stringWrit e.ToString());
HttpContext.Cur rent.Response.E nd();
}

I am calling this by the following code:

protected void btnDownloadDebi t_Click(object sender, EventArgs e)
{
grvDebit.Column s[5].Visible = false;
Util.ExportExce lFile(grvDebit, "DebitDetai l");
grvDebit.Column s[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 1259

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

Similar topics

5
7582
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 sheet, and I would like that they do not know at all that the columns exist. I tried creating a view for them (qryAllData) that only selects the columns that should be visible, but when the creating the ODBC-connection, both the query and the...
5
1638
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 gridview.columns(i).visible property,but it did't work. Thanks in advance Srinivas
0
1022
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 gridview to Excel?
2
1656
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 enter the amount of items being added/removed. When the user clicks the 'Edit' link I want to hide the stock column and display a field for the TransactionAmt. I'm using the RowUpdating event to execute some functions used by that field. I've...
1
1821
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 void gvLocations_edit(object sender, GridViewEditEventArgs e) { // load the record details into the edit fields // GridView gvRecord = (GridView)sender; string sThisRecord = gvRecord.Rows.Cells.Text; ...
2
2911
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 Visible property on the columns it causes the underlying ObjectDataSource to re-issue the Select statement. How can I hide these columns without double clutching the ODS Select?
9
2896
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" in the TemplateField declaration. This column is later used as an UpdateParameter field. Now if I leave the field as Visible="true", everything works fine and down in my C# code, I can easily access the UpdateParameter field with...
6
18578
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 datasource they are added just for dislay. The user fills the data in columns(textboxes) and saves the grid as excel. Can anybody give an idea about adding columns, if possible figureout the sample code. Thanking you all,
9
12096
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; e.Row.Cells.Visible = false; but after that paging is not working. I tried another way by using gridview's column.Visible property but its giving error
0
9474
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
10306
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
10139
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...
1
10075
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
9931
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
6727
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();...
1
4037
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
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
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.