Hiding DataGrid Columns when AutoGenerateColumns="true"

Discussion in 'ASP .Net Datagrid Control' started by Jerad Rose, Mar 13, 2007.

  1. Jerad Rose

    Jerad Rose Guest

    I am working with a DataGrid (ASP.NET 2.0) that is set to
    AutoGenerateColumns="true". It is being populated from a DataSet. There is
    a column that I want to hide from the display, but I want to leave it in the
    DataSet so that it can be referenced. However, all attempts that I've tried
    are failing.

    The main method I see being used is this:

    myColumn.ColumnMapping = MappingType.Hidden

    However, this isn't working -- the column remains visible.

    If I do this:

    myDataTable.Columns.Remove("MyColumn")

    Then the column is hidden, but of course, this removes it from the dataset.

    Of course, I can't hide the column after the DataGrid is bound, because the
    Columns collection isn't populated when using AutoGenerateColumns="true"
    (the reason for this still baffles me, but I've given up on figuring that
    one out).

    I'm aware that I could hide each individual cell on ItemDataBound, but this
    requires referencing the cell through a numeric index, which is a poor
    practice, IMO (what if the order of the columns changes?).

    Here is the full code block:

    Dim myDataSet As DataSet = GetDataSet()

    myDataSet.Tables("Table").Columns("MyColumn").ColumnMapping =
    MappingType.Hidden

    DataGrid1.DataSource = myDataTable
    DataGrid1.DataBind()

    Is there not a way to hide a column for a DataGrid that is using
    AutoGenerateColumns="true", by referencing the column by name?

    Thanks in advance for your help.

    Jerad
     
    Jerad Rose, Mar 13, 2007
    #1
    1. Advertising

  2. You can catch autocreated columns (an hide them) in ItemCreated event.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Jerad Rose" <> wrote in message
    news:...
    >I am working with a DataGrid (ASP.NET 2.0) that is set to
    >AutoGenerateColumns="true". It is being populated from a DataSet. There
    >is a column that I want to hide from the display, but I want to leave it in
    >the DataSet so that it can be referenced. However, all attempts that I've
    >tried are failing.
    >
    > The main method I see being used is this:
    >
    > myColumn.ColumnMapping = MappingType.Hidden
    >
    > However, this isn't working -- the column remains visible.
    >
    > If I do this:
    >
    > myDataTable.Columns.Remove("MyColumn")
    >
    > Then the column is hidden, but of course, this removes it from the
    > dataset.
    >
    > Of course, I can't hide the column after the DataGrid is bound, because
    > the Columns collection isn't populated when using
    > AutoGenerateColumns="true" (the reason for this still baffles me, but I've
    > given up on figuring that one out).
    >
    > I'm aware that I could hide each individual cell on ItemDataBound, but
    > this requires referencing the cell through a numeric index, which is a
    > poor practice, IMO (what if the order of the columns changes?).
    >
    > Here is the full code block:
    >
    > Dim myDataSet As DataSet = GetDataSet()
    >
    > myDataSet.Tables("Table").Columns("MyColumn").ColumnMapping =
    > MappingType.Hidden
    >
    > DataGrid1.DataSource = myDataTable
    > DataGrid1.DataBind()
    >
    > Is there not a way to hide a column for a DataGrid that is using
    > AutoGenerateColumns="true", by referencing the column by name?
    >
    > Thanks in advance for your help.
    >
    > Jerad
    >
     
    Eliyahu Goldin, Mar 13, 2007
    #2
    1. Advertising

  3. Jerad Rose

    Jerad Rose Guest

    Thanks for the response.

    Unfortunately, I don't see how I can use this event to hide a column. This
    event is fired when creating row items, not columns (it passes
    DataGridItemEventArgs, same as the ItemDataBound event). I still do not
    seem to have access to any sort of collection or object representing the
    column I want to hide.

    Can you elaborate on how I can achieve this through this event?

    Thanks again.

    Jerad

    "Eliyahu Goldin" <> wrote in
    message news:...
    > You can catch autocreated columns (an hide them) in ItemCreated event.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Jerad Rose" <> wrote in message
    > news:...
    >>I am working with a DataGrid (ASP.NET 2.0) that is set to
    >>AutoGenerateColumns="true". It is being populated from a DataSet. There
    >>is a column that I want to hide from the display, but I want to leave it
    >>in the DataSet so that it can be referenced. However, all attempts that
    >>I've tried are failing.
    >>
    >> The main method I see being used is this:
    >>
    >> myColumn.ColumnMapping = MappingType.Hidden
    >>
    >> However, this isn't working -- the column remains visible.
    >>
    >> If I do this:
    >>
    >> myDataTable.Columns.Remove("MyColumn")
    >>
    >> Then the column is hidden, but of course, this removes it from the
    >> dataset.
    >>
    >> Of course, I can't hide the column after the DataGrid is bound, because
    >> the Columns collection isn't populated when using
    >> AutoGenerateColumns="true" (the reason for this still baffles me, but
    >> I've given up on figuring that one out).
    >>
    >> I'm aware that I could hide each individual cell on ItemDataBound, but
    >> this requires referencing the cell through a numeric index, which is a
    >> poor practice, IMO (what if the order of the columns changes?).
    >>
    >> Here is the full code block:
    >>
    >> Dim myDataSet As DataSet = GetDataSet()
    >>
    >> myDataSet.Tables("Table").Columns("MyColumn").ColumnMapping =
    >> MappingType.Hidden
    >>
    >> DataGrid1.DataSource = myDataTable
    >> DataGrid1.DataBind()
    >>
    >> Is there not a way to hide a column for a DataGrid that is using
    >> AutoGenerateColumns="true", by referencing the column by name?
    >>
    >> Thanks in advance for your help.
    >>
    >> Jerad
    >>

    >
    >
     
    Jerad Rose, Mar 14, 2007
    #3
  4. In this event you should be able to locate the cell belonging to the column
    you want to hide. You can hide the column by hiding individual cells.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "Jerad Rose" <> wrote in message
    news:...
    > Thanks for the response.
    >
    > Unfortunately, I don't see how I can use this event to hide a column.

    This
    > event is fired when creating row items, not columns (it passes
    > DataGridItemEventArgs, same as the ItemDataBound event). I still do not
    > seem to have access to any sort of collection or object representing the
    > column I want to hide.
    >
    > Can you elaborate on how I can achieve this through this event?
    >
    > Thanks again.
    >
    > Jerad
    >
    > "Eliyahu Goldin" <> wrote in
    > message news:...
    > > You can catch autocreated columns (an hide them) in ItemCreated event.
    > >
    > > --
    > > Eliyahu Goldin,
    > > Software Developer & Consultant
    > > Microsoft MVP [ASP.NET]
    > > http://msmvps.com/blogs/egoldin
    > > http://usableasp.net
    > >
    > >
    > > "Jerad Rose" <> wrote in message
    > > news:...
    > >>I am working with a DataGrid (ASP.NET 2.0) that is set to
    > >>AutoGenerateColumns="true". It is being populated from a DataSet.

    There
    > >>is a column that I want to hide from the display, but I want to leave it
    > >>in the DataSet so that it can be referenced. However, all attempts that
    > >>I've tried are failing.
    > >>
    > >> The main method I see being used is this:
    > >>
    > >> myColumn.ColumnMapping = MappingType.Hidden
    > >>
    > >> However, this isn't working -- the column remains visible.
    > >>
    > >> If I do this:
    > >>
    > >> myDataTable.Columns.Remove("MyColumn")
    > >>
    > >> Then the column is hidden, but of course, this removes it from the
    > >> dataset.
    > >>
    > >> Of course, I can't hide the column after the DataGrid is bound, because
    > >> the Columns collection isn't populated when using
    > >> AutoGenerateColumns="true" (the reason for this still baffles me, but
    > >> I've given up on figuring that one out).
    > >>
    > >> I'm aware that I could hide each individual cell on ItemDataBound, but
    > >> this requires referencing the cell through a numeric index, which is a
    > >> poor practice, IMO (what if the order of the columns changes?).
    > >>
    > >> Here is the full code block:
    > >>
    > >> Dim myDataSet As DataSet = GetDataSet()
    > >>
    > >> myDataSet.Tables("Table").Columns("MyColumn").ColumnMapping =
    > >> MappingType.Hidden
    > >>
    > >> DataGrid1.DataSource = myDataTable
    > >> DataGrid1.DataBind()
    > >>
    > >> Is there not a way to hide a column for a DataGrid that is using
    > >> AutoGenerateColumns="true", by referencing the column by name?
    > >>
    > >> Thanks in advance for your help.
    > >>
    > >> Jerad
    > >>

    > >
    > >

    >
    >
     
    Eliyahu Goldin, Mar 14, 2007
    #4
  5. Jerad Rose

    Jerad Rose Guest

    Thanks again for your response, Eliyahu.

    I mentioned this in my origninal post, but I prefer not to use this method,
    as it requires that I use an ordinal reference and I feel this is a poor
    practice, since it depends on the column order not changing. I would like
    to find a solution that allows me to reference the column by name, and then
    hide it.

    Is this not possible with my situation?

    Thanks.
    Jerad

    "Eliyahu Goldin" <> wrote in
    message news:%...
    > In this event you should be able to locate the cell belonging to the
    > column
    > you want to hide. You can hide the column by hiding individual cells.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    >
    >
    > "Jerad Rose" <> wrote in message
    > news:...
    >> Thanks for the response.
    >>
    >> Unfortunately, I don't see how I can use this event to hide a column.

    > This
    >> event is fired when creating row items, not columns (it passes
    >> DataGridItemEventArgs, same as the ItemDataBound event). I still do not
    >> seem to have access to any sort of collection or object representing the
    >> column I want to hide.
    >>
    >> Can you elaborate on how I can achieve this through this event?
    >>
    >> Thanks again.
    >>
    >> Jerad
    >>
    >> "Eliyahu Goldin" <> wrote in
    >> message news:...
    >> > You can catch autocreated columns (an hide them) in ItemCreated event.
    >> >
    >> > --
    >> > Eliyahu Goldin,
    >> > Software Developer & Consultant
    >> > Microsoft MVP [ASP.NET]
    >> > http://msmvps.com/blogs/egoldin
    >> > http://usableasp.net
    >> >
    >> >
    >> > "Jerad Rose" <> wrote in message
    >> > news:...
    >> >>I am working with a DataGrid (ASP.NET 2.0) that is set to
    >> >>AutoGenerateColumns="true". It is being populated from a DataSet.

    > There
    >> >>is a column that I want to hide from the display, but I want to leave
    >> >>it
    >> >>in the DataSet so that it can be referenced. However, all attempts
    >> >>that
    >> >>I've tried are failing.
    >> >>
    >> >> The main method I see being used is this:
    >> >>
    >> >> myColumn.ColumnMapping = MappingType.Hidden
    >> >>
    >> >> However, this isn't working -- the column remains visible.
    >> >>
    >> >> If I do this:
    >> >>
    >> >> myDataTable.Columns.Remove("MyColumn")
    >> >>
    >> >> Then the column is hidden, but of course, this removes it from the
    >> >> dataset.
    >> >>
    >> >> Of course, I can't hide the column after the DataGrid is bound,
    >> >> because
    >> >> the Columns collection isn't populated when using
    >> >> AutoGenerateColumns="true" (the reason for this still baffles me, but
    >> >> I've given up on figuring that one out).
    >> >>
    >> >> I'm aware that I could hide each individual cell on ItemDataBound, but
    >> >> this requires referencing the cell through a numeric index, which is a
    >> >> poor practice, IMO (what if the order of the columns changes?).
    >> >>
    >> >> Here is the full code block:
    >> >>
    >> >> Dim myDataSet As DataSet = GetDataSet()
    >> >>
    >> >> myDataSet.Tables("Table").Columns("MyColumn").ColumnMapping =
    >> >> MappingType.Hidden
    >> >>
    >> >> DataGrid1.DataSource = myDataTable
    >> >> DataGrid1.DataBind()
    >> >>
    >> >> Is there not a way to hide a column for a DataGrid that is using
    >> >> AutoGenerateColumns="true", by referencing the column by name?
    >> >>
    >> >> Thanks in advance for your help.
    >> >>
    >> >> Jerad
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
     
    Jerad Rose, Mar 14, 2007
    #5
  6. There is an easily solution to this. In the same ItemCreated event detect
    the Header item and locate in it's Cells collection the cell with the text
    matching your column name. Remember the order of this cell and use it as an
    index for data items.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Jerad Rose" <> wrote in message
    news:...
    > Thanks again for your response, Eliyahu.
    >
    > I mentioned this in my origninal post, but I prefer not to use this
    > method, as it requires that I use an ordinal reference and I feel this is
    > a poor practice, since it depends on the column order not changing. I
    > would like to find a solution that allows me to reference the column by
    > name, and then hide it.
    >
    > Is this not possible with my situation?
    >
    > Thanks.
    > Jerad
    >
    > "Eliyahu Goldin" <> wrote in
    > message news:%...
    >> In this event you should be able to locate the cell belonging to the
    >> column
    >> you want to hide. You can hide the column by hiding individual cells.
    >>
    >> --
    >> Eliyahu Goldin,
    >> Software Developer & Consultant
    >> Microsoft MVP [ASP.NET]
    >> http://msmvps.com/blogs/egoldin
    >>
    >>
    >> "Jerad Rose" <> wrote in message
    >> news:...
    >>> Thanks for the response.
    >>>
    >>> Unfortunately, I don't see how I can use this event to hide a column.

    >> This
    >>> event is fired when creating row items, not columns (it passes
    >>> DataGridItemEventArgs, same as the ItemDataBound event). I still do not
    >>> seem to have access to any sort of collection or object representing the
    >>> column I want to hide.
    >>>
    >>> Can you elaborate on how I can achieve this through this event?
    >>>
    >>> Thanks again.
    >>>
    >>> Jerad
    >>>
    >>> "Eliyahu Goldin" <> wrote in
    >>> message news:...
    >>> > You can catch autocreated columns (an hide them) in ItemCreated event.
    >>> >
    >>> > --
    >>> > Eliyahu Goldin,
    >>> > Software Developer & Consultant
    >>> > Microsoft MVP [ASP.NET]
    >>> > http://msmvps.com/blogs/egoldin
    >>> > http://usableasp.net
    >>> >
    >>> >
    >>> > "Jerad Rose" <> wrote in message
    >>> > news:...
    >>> >>I am working with a DataGrid (ASP.NET 2.0) that is set to
    >>> >>AutoGenerateColumns="true". It is being populated from a DataSet.

    >> There
    >>> >>is a column that I want to hide from the display, but I want to leave
    >>> >>it
    >>> >>in the DataSet so that it can be referenced. However, all attempts
    >>> >>that
    >>> >>I've tried are failing.
    >>> >>
    >>> >> The main method I see being used is this:
    >>> >>
    >>> >> myColumn.ColumnMapping = MappingType.Hidden
    >>> >>
    >>> >> However, this isn't working -- the column remains visible.
    >>> >>
    >>> >> If I do this:
    >>> >>
    >>> >> myDataTable.Columns.Remove("MyColumn")
    >>> >>
    >>> >> Then the column is hidden, but of course, this removes it from the
    >>> >> dataset.
    >>> >>
    >>> >> Of course, I can't hide the column after the DataGrid is bound,
    >>> >> because
    >>> >> the Columns collection isn't populated when using
    >>> >> AutoGenerateColumns="true" (the reason for this still baffles me, but
    >>> >> I've given up on figuring that one out).
    >>> >>
    >>> >> I'm aware that I could hide each individual cell on ItemDataBound,
    >>> >> but
    >>> >> this requires referencing the cell through a numeric index, which is
    >>> >> a
    >>> >> poor practice, IMO (what if the order of the columns changes?).
    >>> >>
    >>> >> Here is the full code block:
    >>> >>
    >>> >> Dim myDataSet As DataSet = GetDataSet()
    >>> >>
    >>> >> myDataSet.Tables("Table").Columns("MyColumn").ColumnMapping =
    >>> >> MappingType.Hidden
    >>> >>
    >>> >> DataGrid1.DataSource = myDataTable
    >>> >> DataGrid1.DataBind()
    >>> >>
    >>> >> Is there not a way to hide a column for a DataGrid that is using
    >>> >> AutoGenerateColumns="true", by referencing the column by name?
    >>> >>
    >>> >> Thanks in advance for your help.
    >>> >>
    >>> >> Jerad
    >>> >>
    >>> >
    >>> >
    >>>
    >>>

    >>
    >>

    >
    >
     
    Eliyahu Goldin, Mar 14, 2007
    #6
  7. I don't know. There must be a reason for this. MS does care of the
    developers and if a feature is not there there should be a reason.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Jerad Rose" <> wrote in message
    news:O0%...
    > Thansk again, Eliyahu.
    >
    > This sounds like it might work as a workaround, but it's definitely not a
    > very elegant approach. So it sounds like there is no built-in method that
    > .NET supports? Is there a reason why this ability isn't there? Is it an
    > oversight, or is it a bug?
    >
    > For example, to me, it would make much more sense if either:
    >
    > a) the DataGrid Columns collection *was* populated with autogenerated
    > columns, instead of being completely empty
    > b) setting the ColumnMapping to Hidden *did* work
    >
    > Is there any logical explanation as to why neither of these is the case?
    >
    > Thanks again.
    >
    > Jerad
    >
    > "Eliyahu Goldin" <> wrote in
    > message news:%23SXdq$...
    >> There is an easily solution to this. In the same ItemCreated event detect
    >> the Header item and locate in it's Cells collection the cell with the
    >> text
    >> matching your column name. Remember the order of this cell and use it as

    > an
    >> index for data items.
    >>
    >> --
    >> Eliyahu Goldin,
    >> Software Developer & Consultant
    >> Microsoft MVP [ASP.NET]
    >> http://msmvps.com/blogs/egoldin
    >> http://usableasp.net
    >>
    >>
    >> "Jerad Rose" <> wrote in message
    >> news:...
    >> > Thanks again for your response, Eliyahu.
    >> >
    >> > I mentioned this in my origninal post, but I prefer not to use this
    >> > method, as it requires that I use an ordinal reference and I feel this

    > is
    >> > a poor practice, since it depends on the column order not changing. I
    >> > would like to find a solution that allows me to reference the column by
    >> > name, and then hide it.
    >> >
    >> > Is this not possible with my situation?
    >> >
    >> > Thanks.
    >> > Jerad
    >> >
    >> > "Eliyahu Goldin" <> wrote in
    >> > message news:%...
    >> >> In this event you should be able to locate the cell belonging to the
    >> >> column
    >> >> you want to hide. You can hide the column by hiding individual cells.
    >> >>
    >> >> --
    >> >> Eliyahu Goldin,
    >> >> Software Developer & Consultant
    >> >> Microsoft MVP [ASP.NET]
    >> >> http://msmvps.com/blogs/egoldin
    >> >>
    >> >>
    >> >> "Jerad Rose" <> wrote in message
    >> >> news:...
    >> >>> Thanks for the response.
    >> >>>
    >> >>> Unfortunately, I don't see how I can use this event to hide a column.
    >> >> This
    >> >>> event is fired when creating row items, not columns (it passes
    >> >>> DataGridItemEventArgs, same as the ItemDataBound event). I still do

    > not
    >> >>> seem to have access to any sort of collection or object representing

    > the
    >> >>> column I want to hide.
    >> >>>
    >> >>> Can you elaborate on how I can achieve this through this event?
    >> >>>
    >> >>> Thanks again.
    >> >>>
    >> >>> Jerad
    >> >>>
    >> >>> "Eliyahu Goldin" <> wrote in
    >> >>> message news:...
    >> >>> > You can catch autocreated columns (an hide them) in ItemCreated

    > event.
    >> >>> >
    >> >>> > --
    >> >>> > Eliyahu Goldin,
    >> >>> > Software Developer & Consultant
    >> >>> > Microsoft MVP [ASP.NET]
    >> >>> > http://msmvps.com/blogs/egoldin
    >> >>> > http://usableasp.net
    >> >>> >
    >> >>> >
    >> >>> > "Jerad Rose" <> wrote in message
    >> >>> > news:...
    >> >>> >>I am working with a DataGrid (ASP.NET 2.0) that is set to
    >> >>> >>AutoGenerateColumns="true". It is being populated from a DataSet.
    >> >> There
    >> >>> >>is a column that I want to hide from the display, but I want to

    > leave
    >> >>> >>it
    >> >>> >>in the DataSet so that it can be referenced. However, all attempts
    >> >>> >>that
    >> >>> >>I've tried are failing.
    >> >>> >>
    >> >>> >> The main method I see being used is this:
    >> >>> >>
    >> >>> >> myColumn.ColumnMapping = MappingType.Hidden
    >> >>> >>
    >> >>> >> However, this isn't working -- the column remains visible.
    >> >>> >>
    >> >>> >> If I do this:
    >> >>> >>
    >> >>> >> myDataTable.Columns.Remove("MyColumn")
    >> >>> >>
    >> >>> >> Then the column is hidden, but of course, this removes it from the
    >> >>> >> dataset.
    >> >>> >>
    >> >>> >> Of course, I can't hide the column after the DataGrid is bound,
    >> >>> >> because
    >> >>> >> the Columns collection isn't populated when using
    >> >>> >> AutoGenerateColumns="true" (the reason for this still baffles me,

    > but
    >> >>> >> I've given up on figuring that one out).
    >> >>> >>
    >> >>> >> I'm aware that I could hide each individual cell on ItemDataBound,
    >> >>> >> but
    >> >>> >> this requires referencing the cell through a numeric index, which

    > is
    >> >>> >> a
    >> >>> >> poor practice, IMO (what if the order of the columns changes?).
    >> >>> >>
    >> >>> >> Here is the full code block:
    >> >>> >>
    >> >>> >> Dim myDataSet As DataSet = GetDataSet()
    >> >>> >>
    >> >>> >> myDataSet.Tables("Table").Columns("MyColumn").ColumnMapping

    > =
    >> >>> >> MappingType.Hidden
    >> >>> >>
    >> >>> >> DataGrid1.DataSource = myDataTable
    >> >>> >> DataGrid1.DataBind()
    >> >>> >>
    >> >>> >> Is there not a way to hide a column for a DataGrid that is using
    >> >>> >> AutoGenerateColumns="true", by referencing the column by name?
    >> >>> >>
    >> >>> >> Thanks in advance for your help.
    >> >>> >>
    >> >>> >> Jerad
    >> >>> >>
    >> >>> >
    >> >>> >
    >> >>>
    >> >>>
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
     
    Eliyahu Goldin, Mar 14, 2007
    #7
  8. Jerad Rose

    Jerad Rose Guest

    Thansk again, Eliyahu.

    This sounds like it might work as a workaround, but it's definitely not a
    very elegant approach. So it sounds like there is no built-in method that
    ..NET supports? Is there a reason why this ability isn't there? Is it an
    oversight, or is it a bug?

    For example, to me, it would make much more sense if either:

    a) the DataGrid Columns collection *was* populated with autogenerated
    columns, instead of being completely empty
    b) setting the ColumnMapping to Hidden *did* work

    Is there any logical explanation as to why neither of these is the case?

    Thanks again.

    Jerad

    "Eliyahu Goldin" <> wrote in
    message news:%23SXdq$...
    > There is an easily solution to this. In the same ItemCreated event detect
    > the Header item and locate in it's Cells collection the cell with the text
    > matching your column name. Remember the order of this cell and use it as

    an
    > index for data items.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Jerad Rose" <> wrote in message
    > news:...
    > > Thanks again for your response, Eliyahu.
    > >
    > > I mentioned this in my origninal post, but I prefer not to use this
    > > method, as it requires that I use an ordinal reference and I feel this

    is
    > > a poor practice, since it depends on the column order not changing. I
    > > would like to find a solution that allows me to reference the column by
    > > name, and then hide it.
    > >
    > > Is this not possible with my situation?
    > >
    > > Thanks.
    > > Jerad
    > >
    > > "Eliyahu Goldin" <> wrote in
    > > message news:%...
    > >> In this event you should be able to locate the cell belonging to the
    > >> column
    > >> you want to hide. You can hide the column by hiding individual cells.
    > >>
    > >> --
    > >> Eliyahu Goldin,
    > >> Software Developer & Consultant
    > >> Microsoft MVP [ASP.NET]
    > >> http://msmvps.com/blogs/egoldin
    > >>
    > >>
    > >> "Jerad Rose" <> wrote in message
    > >> news:...
    > >>> Thanks for the response.
    > >>>
    > >>> Unfortunately, I don't see how I can use this event to hide a column.
    > >> This
    > >>> event is fired when creating row items, not columns (it passes
    > >>> DataGridItemEventArgs, same as the ItemDataBound event). I still do

    not
    > >>> seem to have access to any sort of collection or object representing

    the
    > >>> column I want to hide.
    > >>>
    > >>> Can you elaborate on how I can achieve this through this event?
    > >>>
    > >>> Thanks again.
    > >>>
    > >>> Jerad
    > >>>
    > >>> "Eliyahu Goldin" <> wrote in
    > >>> message news:...
    > >>> > You can catch autocreated columns (an hide them) in ItemCreated

    event.
    > >>> >
    > >>> > --
    > >>> > Eliyahu Goldin,
    > >>> > Software Developer & Consultant
    > >>> > Microsoft MVP [ASP.NET]
    > >>> > http://msmvps.com/blogs/egoldin
    > >>> > http://usableasp.net
    > >>> >
    > >>> >
    > >>> > "Jerad Rose" <> wrote in message
    > >>> > news:...
    > >>> >>I am working with a DataGrid (ASP.NET 2.0) that is set to
    > >>> >>AutoGenerateColumns="true". It is being populated from a DataSet.
    > >> There
    > >>> >>is a column that I want to hide from the display, but I want to

    leave
    > >>> >>it
    > >>> >>in the DataSet so that it can be referenced. However, all attempts
    > >>> >>that
    > >>> >>I've tried are failing.
    > >>> >>
    > >>> >> The main method I see being used is this:
    > >>> >>
    > >>> >> myColumn.ColumnMapping = MappingType.Hidden
    > >>> >>
    > >>> >> However, this isn't working -- the column remains visible.
    > >>> >>
    > >>> >> If I do this:
    > >>> >>
    > >>> >> myDataTable.Columns.Remove("MyColumn")
    > >>> >>
    > >>> >> Then the column is hidden, but of course, this removes it from the
    > >>> >> dataset.
    > >>> >>
    > >>> >> Of course, I can't hide the column after the DataGrid is bound,
    > >>> >> because
    > >>> >> the Columns collection isn't populated when using
    > >>> >> AutoGenerateColumns="true" (the reason for this still baffles me,

    but
    > >>> >> I've given up on figuring that one out).
    > >>> >>
    > >>> >> I'm aware that I could hide each individual cell on ItemDataBound,
    > >>> >> but
    > >>> >> this requires referencing the cell through a numeric index, which

    is
    > >>> >> a
    > >>> >> poor practice, IMO (what if the order of the columns changes?).
    > >>> >>
    > >>> >> Here is the full code block:
    > >>> >>
    > >>> >> Dim myDataSet As DataSet = GetDataSet()
    > >>> >>
    > >>> >> myDataSet.Tables("Table").Columns("MyColumn").ColumnMapping

    =
    > >>> >> MappingType.Hidden
    > >>> >>
    > >>> >> DataGrid1.DataSource = myDataTable
    > >>> >> DataGrid1.DataBind()
    > >>> >>
    > >>> >> Is there not a way to hide a column for a DataGrid that is using
    > >>> >> AutoGenerateColumns="true", by referencing the column by name?
    > >>> >>
    > >>> >> Thanks in advance for your help.
    > >>> >>
    > >>> >> Jerad
    > >>> >>
    > >>> >
    > >>> >
    > >>>
    > >>>
    > >>
    > >>

    > >
    > >

    >
    >
     
    Jerad Rose, Mar 14, 2007
    #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. David M. Weprin
    Replies:
    0
    Views:
    442
    David M. Weprin
    Oct 16, 2003
  2. Andy Sutorius
    Replies:
    2
    Views:
    2,185
    Sandeep Kayal
    Jun 30, 2004
  3. bdb112
    Replies:
    45
    Views:
    1,420
    jazbees
    Apr 29, 2009
  4. Amrut Kale

    Using AutoGenerateColumns to generate Datagrid columns

    Amrut Kale, Sep 29, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    218
    Amrut Kale
    Sep 29, 2003
  5. ton
    Replies:
    2
    Views:
    217
    Alvin Bruney [MVP]
    Feb 11, 2004
Loading...

Share This Page