Trying to hide a datatable column from my datagrid... please help

  • Thread starter Thread starter jonnylbluejeans
  • Start date Start date
J

jonnylbluejeans

I've read everywhere to use the following:

objDS.Tables("Results").Columns(0).ColumnMapping = MappingType.Hidden

objDS.AcceptChanges()

dgNotes.DataSource = objDS.Tables("Results")

dgNotes.DataBind()



But, the column still shows? Can anyone shed some light on this?
 
jonny,

I haven't seen any code like you're using before.

I hide columns by simply setting the column's visibility property.

Here's how I do it when I'm creating the datagrid myself:

<asp:boundcolumn visible="False" datafield="pk_EntryId"></asp:boundcolumn>

And here's how I set it from the codebehind:

DataGrid1.Columns(0).Visible = False

I hope this helps.
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Use the ItemCreated Event to
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated

Select Case e.Item.ItemType

Case ListItemType.Header,ListItemType.AlternativeItem,ListItemType....

e.Item.Cells(1).Visible = False


End Sub
 
Thanks for this one! It solved a different problem for me:

If I set a column's Visible property to False (unchecking in the columns
property page), the value read from it is empty. Using this technique makes
the column invisible without causing that side-effect.

Frankly, in the case of my problem, I think it's a bug!! But, whatever it
takes....
 
Back
Top