Hide a column?

D

dew

How do I hide a column when using AutoGenerateColumns turned on? I tried
dg.Columns(1).visible = false but it errors, as if there is no column.

Also in ItemDataBound, I tried e.items.Cells(1).visible = false and it does
hide that cell, but it doesn't hide the column, so the header of that column
still appears.

This grid has to be auto-generated because there are about 20 queries of
where the datasource is coming from, I don't want to have to make 20 grids
with 20 different queries just to eliminate the id field. Any ideas?

Thanks for your help.
 
E

Elton Wang

In either ItemCreated or ItemDataBound event (without any condition):

e.items.Cells(col_index).Visible = False

will set the whole column invisible.

HTH
 
M

mkhmer

Well, this is my error received by using your suggestion code to hide a
specific column of DataGrid:

===============
BC30456: 'items' is not a member of
'System.Web.UI.WebControls.DataGridItemEventArgs
===============

If you have any idea on that error cause?

Mkhmer
 

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,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top