Hide Columns in GridView?

Discussion in 'ASP .Net' started by Phil Sandler, Dec 21, 2006.

  1. Phil Sandler

    Phil Sandler Guest

    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
    Phil Sandler, Dec 21, 2006
    #1
    1. Advertising

  2. 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
    >
    >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=, Dec 22, 2006
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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
    >
    Eliyahu Goldin, Dec 22, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason
    Replies:
    3
    Views:
    17,047
    Jan Hyde
    May 8, 2006
  2. =?Utf-8?B?Q1NoYXJwZ3V5?=

    hide columns in export of gridview

    =?Utf-8?B?Q1NoYXJwZ3V5?=, Sep 7, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    481
    =?Utf-8?B?Q1NoYXJwZ3V5?=
    Sep 7, 2006
  3. =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=

    Hide a few (variable) columns in a GridView

    =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=, Feb 13, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    818
    Alexey Smirnov
    Feb 15, 2007
  4. David C

    Hide GridView Columns

    David C, Feb 29, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    558
    David C
    Feb 29, 2008
  5. DavidC

    Hide columns in GridView

    DavidC, Feb 3, 2010, in forum: ASP .Net
    Replies:
    1
    Views:
    2,560
    PvdG42
    Feb 3, 2010
Loading...

Share This Page