Hide a column in asp:GridView

Discussion in 'ASP .Net' started by ghostwolf, Aug 4, 2006.

  1. ghostwolf

    ghostwolf Guest

    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 <div> inside for setting it
    display:none. What can I do? Thanks in millions.
    ghostwolf, Aug 4, 2006
    #1
    1. Advertising

  2. To hide the third column for example ...

    GridView.Columns[2].Visible = false;

    "ghostwolf" wrote:

    > 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 <div> inside for setting it
    > display:none. What can I do? Thanks in millions.
    >
    >
    >
    =?Utf-8?B?Y2xpY2tvbg==?=, Aug 4, 2006
    #2
    1. Advertising

  3. ghostwolf

    Mark Rae Guest

    "ghostwolf" <> wrote in message
    news:...

    > 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 <div> inside for setting it
    > display:none. What can I do? Thanks in millions.


    MyGridView.Columns[0].Visible = false;

    HOWEVER, bear in mind that this isn't actually *hiding* the column per se -
    it's physically *removing* the column from the HTML being sent down to the
    client, which may not be what you really want...
    Mark Rae, Aug 4, 2006
    #3
  4. ghostwolf

    ghostwolf Guest

    thanks, actually I don't really want to invisible it. It is because I want
    to put a value for each row but make it hide away. Just like what we did in
    windows programming for adding a value for each row. If I make the column in
    asp:GridView invisible, I cannot get the value from that column.

    "Mark Rae" <> wrote in message
    news:...
    > "ghostwolf" <> wrote in message
    > news:...
    >
    >> 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 <div> inside for setting it
    >> display:none. What can I do? Thanks in millions.

    >
    > MyGridView.Columns[0].Visible = false;
    >
    > HOWEVER, bear in mind that this isn't actually *hiding* the column per
    > se - it's physically *removing* the column from the HTML being sent down
    > to the client, which may not be what you really want...
    >
    ghostwolf, Aug 4, 2006
    #4
  5. ghostwolf

    Mark Rae Guest

    "ghostwolf" <> wrote in message
    news:O4v$...

    > thanks, actually I don't really want to invisible it. It is because I want
    > to put a value for each row but make it hide away. Just like what we did
    > in windows programming for adding a value for each row. If I make the
    > column in asp:GridView invisible, I cannot get the value from that column.


    Ah... You've discovered the additional security feature that a GridView has
    but a DataGrid didn't.

    Basically, Microsoft took the view that using hidden columns to store data
    was a potential security risk, so they removed hidden colums from ViewState
    at databind time. However, it's easy enough to work round, but be aware of
    the potential security risk involved in doing this...

    MyGridView.DataSource = <datasource>;
    MyGridView.Columns[0].Visible = true;
    MyGridView.DataBind();
    MyGridView.Columns[0].Visible = false;
    Mark Rae, Aug 4, 2006
    #5
  6. ghostwolf

    Winista Guest

    Check this out..

    http://www.netomatix.com/development/GridViewHideColumn.aspx

    "ghostwolf" <> wrote in message
    news:...
    > 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 <div> inside for setting it
    > display:none. What can I do? Thanks in millions.
    >
    Winista, Aug 4, 2006
    #6
  7. ghostwolf

    Mark Rae Guest

    Mark Rae, Aug 4, 2006
    #7
  8. ghostwolf

    Winista Guest

    Thank you for pointing out the issue with the approach. It has been fixed on
    the site as well as attached demo project.

    "Mark Rae" <> wrote in message
    news:...
    > "Winista" <> wrote in message
    > news:...
    >
    >> Check this out..
    >>
    >> http://www.netomatix.com/development/GridViewHideColumn.aspx

    >
    > Correct approach, terrible implementation!
    >
    > Need to set display to either none or block to make this work properly.
    >
    Winista, Aug 4, 2006
    #8
  9. ghostwolf

    Mark Rae Guest

    "Winista" <> wrote in message
    news:u$WE8%...

    > Thank you for pointing out the issue with the approach. It has been fixed
    > on the site as well as attached demo project.


    Excellent. Check this out for cross-browser compatibility
    http://www.quirksmode.org/css/display.html, but I think you're OK... :)
    Mark Rae, Aug 4, 2006
    #9
  10. ghostwolf

    ghostwolf Guest

    Thanks, it's great for me.

    "Mark Rae" <> wrote in message
    news:umI5vD%...
    > "Winista" <> wrote in message
    > news:u$WE8%...
    >
    >> Thank you for pointing out the issue with the approach. It has been fixed
    >> on the site as well as attached demo project.

    >
    > Excellent. Check this out for cross-browser compatibility
    > http://www.quirksmode.org/css/display.html, but I think you're OK... :)
    >
    ghostwolf, Aug 7, 2006
    #10
  11. ghostwolf

    oaksong

    Joined:
    Jun 8, 2009
    Messages:
    1
    columns unavailable after databind

    I tried GridView2.Columns(2).Visible = false and got an error message. I used the immediate window for: ?GridView2.Columns.Count and the result was 0. I stepped past that operation and the grid displays 3 columns. What's going on?
    oaksong, Jun 8, 2009
    #11
    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,057
    Jan Hyde
    May 8, 2006
  2. Keithb

    How to hide a GridView column?

    Keithb, Oct 26, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    881
    Eliyahu Goldin
    Oct 26, 2006
  3. Keithb
    Replies:
    2
    Views:
    1,137
  4. Luqman
    Replies:
    4
    Views:
    5,225
    luqman
    Aug 13, 2007
  5. Keith G Hicks
    Replies:
    3
    Views:
    763
    Keith G Hicks
    Feb 18, 2008
Loading...

Share This Page