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

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?
 
S

S. Justin Gengo

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
 
J

Jerry

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
 
R

Rick Spiewak

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top