473,406 Members | 2,208 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,406 software developers and data experts.

Hide Columns in GridView?

Quick question:

Is it possible to use autogeneratecolumns = true and still hide
specific columns based on the column name in the datasource?

Failing that, can it be done by column index?
Thanks,

Phil

Dec 21 '06 #1
2 7307
Hi Phil,

Yes you can, but it's quite *nasty* - you end up with accessing Controls
collection (as you may know, autogenerated fields are not added to the
Columns collection, they are kept in private variable _autoGenFieldProps -
see it for yourself in quick watch window while debuging), Anyway, here's the
mentioned solution:

foreach (TableRow row in list.Controls[0].Controls)
{
row.Cells[IndexOfTheColumnToHide].Visible = false;
}

You can still do it properly, adding columns programatically based on the
datasource (i know it would require a little bit more codding).

Hope this helps
--
Milosz Skalecki
MCAD
"Phil Sandler" wrote:
Quick question:

Is it possible to use autogeneratecolumns = true and still hide
specific columns based on the column name in the datasource?

Failing that, can it be done by column index?
Thanks,

Phil

Dec 22 '06 #2
Just note that you can catch autogenerated columns in the grid's ItemCreated
event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Phil Sandler" <ps********@hotmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
Quick question:

Is it possible to use autogeneratecolumns = true and still hide
specific columns based on the column name in the datasource?

Failing that, can it be done by column index?
Thanks,

Phil

Dec 22 '06 #3

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

Similar topics

1
by: carmen | last post by:
Hi, I have been searching for information n how to do this for weeks without much success :(. I have a gridview with 15 columns which takes up lots of screenspace. I wanted to be let the users...
3
by: Jason | last post by:
How do I hide a column in a GridView in ASP.NET 2.0 when all of the columns are autogenerated based on the datasource? I want to hide the first of three columns, but the following doesn't work: ...
9
by: ghostwolf | last post by:
Hi, I want to hide a column in the asp:GridView, say one of the column of asp:BoundField. But it is not allowed to put <divinside for setting it display:none. What can I do? Thanks in millions.
0
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...
3
by: kevinpublic | last post by:
I have an item list for ordered products on a data grid in VS 2003. It's an ASP page running VB behind it. All detail lines display as well as all shipping charges. On the edit screen, we allow...
3
by: =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?= | last post by:
Hi, I have a GridView with a fixed number of columns being returned from a SQL query and each having a simple template: <asp:TemplateField HeaderText="Allocations"> <edititemtemplate>...
0
by: Riaaaa | last post by:
I have created the form for entering the company details with its general information in asp.net C# 2005. I have two buttons that form on the submit click event it should saw the newly / last...
4
by: Luqman | last post by:
I have populated the Child Accounts and Parent Accounts in a Grid View Control, I want to hide the Select Column of Parent Accounts, but not the Child Accounts, is it possible ? I am using VS...
3
by: mudassir368 | last post by:
--This is the html code <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> <Columns>...
1
by: Anne | last post by:
Hi, I have a gridview that display questions & answers. In some case the answers are text (up to 5000 char) and other cases they are tick boxes or numbers ($), or date. I have created 2...
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...
0
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...
0
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...
0
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...

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.