Hide Datagrid Column via client side scripting (Javascript)

Discussion in 'ASP .Net' started by Rob, Dec 5, 2005.

  1. Rob

    Rob Guest

    Does anyone know how I could hide a column in a DataGrid? To make the
    problem harder I am using AutoGenerateColumns="True" so I don't know
    how to find the control using document.getElementById(ControlID) and
    then hiding it by using display:none;

    Anyone have any suggestions?

    Thanks for the help.
    Rob, Dec 5, 2005
    #1
    1. Advertising

  2. You know the grid id. It lets you find the table the grid is rendered as.
    The first row of the table contains the column headers. If you know the
    column header text, you can loop through the cells of the first row and find
    the one with the innerText matching the required header text. In this way
    you find out the index of the required column in the row. Then loop through
    the rest of the rows and set display:none for the cell with the required
    index.

    Eliyahu

    "Rob" <> wrote in message
    news:...
    > Does anyone know how I could hide a column in a DataGrid? To make the
    > problem harder I am using AutoGenerateColumns="True" so I don't know
    > how to find the control using document.getElementById(ControlID) and
    > then hiding it by using display:none;
    >
    > Anyone have any suggestions?
    >
    > Thanks for the help.
    >
    Eliyahu Goldin, Dec 6, 2005
    #2
    1. Advertising

  3. Why don't you simply do :
    yourDataGrid.Columns[columnIndex].Visible = false;
    Patrick


    "Rob" <> wrote in message
    news:...
    > Does anyone know how I could hide a column in a DataGrid? To make the
    > problem harder I am using AutoGenerateColumns="True" so I don't know
    > how to find the control using document.getElementById(ControlID) and
    > then hiding it by using display:none;
    >
    > Anyone have any suggestions?
    >
    > Thanks for the help.
    >
    Patrick.O.Ige, Dec 6, 2005
    #3
  4. Patrick,

    Firstly, autogenerated columns don't appear in Columns collection.
    Secondly, the OP is looking for a client-side solution.

    Eliyahu

    "Patrick.O.Ige" <> wrote in message
    news:%23vNprIk%...
    > Why don't you simply do :
    > yourDataGrid.Columns[columnIndex].Visible = false;
    > Patrick
    >
    >
    > "Rob" <> wrote in message
    > news:...
    >> Does anyone know how I could hide a column in a DataGrid? To make the
    >> problem harder I am using AutoGenerateColumns="True" so I don't know
    >> how to find the control using document.getElementById(ControlID) and
    >> then hiding it by using display:none;
    >>
    >> Anyone have any suggestions?
    >>
    >> Thanks for the help.
    >>

    >
    >
    Eliyahu Goldin, Dec 6, 2005
    #4
  5. Rob

    Techotsav Guest

    Rob do u mean by hiding column hiding text or hiding whatever inside
    that cloumn (may be some other controls too)?
    Techotsav, Dec 6, 2005
    #5
  6. Rob

    Rob Guest

    Yes, hiding the entire contents of the column in the autogenerated
    datagrid. Previously I have been using .Visible=false but a round trip
    to the server is too slow.

    I think Eliyahu Goldin has what I am looking for however I am not sure
    I know how to work through the solution. Does anyone have an example
    of this?
    Thanks in advance for the help.
    Rob, Dec 6, 2005
    #6
  7. Basically, you just need to browse through the table DHTML object. Look it
    up in the MSDN library. The online version is here:
    http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/table.asp

    You will find there all properties you need: the collections of rows and
    cells.

    Eliyahu

    "Rob" <> wrote in message
    news:...
    > Yes, hiding the entire contents of the column in the autogenerated
    > datagrid. Previously I have been using .Visible=false but a round trip
    > to the server is too slow.
    >
    > I think Eliyahu Goldin has what I am looking for however I am not sure
    > I know how to work through the solution. Does anyone have an example
    > of this?
    > Thanks in advance for the help.
    >
    Eliyahu Goldin, Dec 6, 2005
    #7
  8. Sorry though i didn't notice the AutoGenerateColumns.

    "Patrick.O.Ige" <> wrote in message
    news:%23vNprIk%...
    > Why don't you simply do :
    > yourDataGrid.Columns[columnIndex].Visible = false;
    > Patrick
    >
    >
    > "Rob" <> wrote in message
    > news:...
    > > Does anyone know how I could hide a column in a DataGrid? To make the
    > > problem harder I am using AutoGenerateColumns="True" so I don't know
    > > how to find the control using document.getElementById(ControlID) and
    > > then hiding it by using display:none;
    > >
    > > Anyone have any suggestions?
    > >
    > > Thanks for the help.
    > >

    >
    >
    Patrick.O.Ige, Dec 7, 2005
    #8
    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. moondaddy
    Replies:
    2
    Views:
    1,029
    Steven Cheng[MSFT]
    Jul 16, 2004
  2. Paul
    Replies:
    2
    Views:
    923
  3. Boss302
    Replies:
    0
    Views:
    1,035
    Boss302
    Nov 21, 2006
  4. James Radke

    Datagrid - can that be refreshed via client side javascript?

    James Radke, Nov 11, 2003, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    651
    James Radke
    Nov 14, 2003
  5. Kathryn
    Replies:
    9
    Views:
    199
    William Morris
    Oct 17, 2003
Loading...

Share This Page