Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Hide Columns in GridView?

Reply
Thread Tools

Hide Columns in GridView?

 
 
Phil Sandler
Guest
Posts: n/a
 
      12-21-2006
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
Guest
Posts: n/a
 
      12-22-2006
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
>
>

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      12-22-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to dynamically hide/unhide dataview columns carmen ASP .Net 1 10-12-2005 04:09 PM
[HIDE LAN] Hide a part of hosts into the LAN at VPN users? Paolo Bresi Cisco 1 04-04-2005 02:41 PM
Hide/Show table columns? Noozer HTML 3 12-01-2004 09:37 PM
how to hide auto generate columns in datagrid? Hanson ASP .Net 8 07-02-2004 10:35 AM
How to hide columns in Datagrid J Gao ASP .Net 1 07-22-2003 02:25 PM



Advertisments