J
Jerad Rose
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
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