Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2013, 04:37 PM
Authorized User
 
Join Date: Feb 2013
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default Hiding columns ion GridView or ListView

Imar:

In your book (Page 530) you say "Additionally, you can tweak these controls to hide specific columns, ...".
I have had no luck hiding columns in a GridView. I have tried adding
Code:
e.Row.Cells[0].Visible=false;
to the RowCreated event but this results in the column not being rendered.

Several blogs talk about the fact that Microsoft decided (starting with Visual Studio 2008) that hiding columns was a security risk at no longer renders any cell that is marked as "visible = false" and consequently the data in that column is not hidden - it is deleted!

One blog suggests that you can set "itemstyle-css" to a "hiddencol" attribute that you define in a style sheet as "display: none;". To do this with a databound GridView you need to set autogeneratecolumns to false so that you can add the "itemstyle-css" to each BoundField in Markup view. However, this does not work.

Do you have any suggestions? Is it possible if I use a ListView instead?
 
Old February 26th, 2013, 05:07 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Several blogs talk about the fact that Microsoft decided (starting with Visual Studio 2008) that hiding columns was a security risk at no longer renders any cell that is marked as "visible = false" and consequently the data in that column is not hidden - it is deleted!
This has always been the case. Visible=False means *server-side visibility*. Something that's not visible at the server is never sent to the browser.

Why do you want to hide it client still, but still include it in the HTML?

The other tip should work: add a CSS class to the column and then hide it using CSS.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 26th, 2013, 06:50 PM
Authorized User
 
Join Date: Feb 2013
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default Hiding Columns in GridView

Imar:

The reason that I want to hide a column is that I am developing a multi-tenant application. Every table ion my DB contains a TenantId column. My EntityDataSource has a "where" clause that filters on the TenantId. Consequently the TenantId must be included in the data and ends up being displayed.

I have solved the problem in the hour or two since I sent you the question. The ItemStyleCssClass = "hiddencol" which is defined as "display: none;" works for the data but does not hide the GridView column heading. Because the headings are generated dynamically it is not possible to assign a CssClass to them. To hide(delete) the column heading I placed the following code in the RowCreated event:

Code:
If (e.Row.RowType = DataControlRowType.Header)
           {
            e.Row.Cells[0].Visible = false;
           }
Once again, thank you for your response. You are very generous with your time.

Robin
 
Old February 27th, 2013, 06:57 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Consequently the TenantId must be included in the data and ends up being displayed.
This isn't true. You don't need a field in a Select statement or a column to include it in a Where clause.

If you still need the TenantId available after a postback, just add it to the DataKeyNames attribute, This way, it's stored and encrypted in ViewState and you don't need to mess with hidden but not not hidden columns.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding Listview Columns? jakeone Beginning VB 6 12 October 2nd, 2008 03:52 PM
Trouble hiding and unhiding columns in VBA jtmelb Excel VBA 0 February 14th, 2007 07:04 PM
Hiding Report Columns gupta_abhinav99 Crystal Reports 1 February 9th, 2007 04:38 AM
hiding / unhiding columns in datagrid drachx General .NET 9 October 18th, 2004 02:37 AM
Dynamically Hiding Columns r_ganesh76 Crystal Reports 1 September 23rd, 2004 11:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.