try this (from datagridgirl.com)
Question: How do I hide a column in my Datagrid if AutoGenerateColumns is
set to True?
Answer: AutoGenerated columns do not appear in the Datagrid's Columns()
collection, and so the usual method of hiding a Datagrid column will fail:
'Will NOT work for AutoGenerated columns:
Datagrid1.Columns(1).Visible = False
So the place to handle this is in the ItemDataBound event of the Datagrid:
<asp

ataGrid id="Datagrid1" runat="server" AutoGenerateColumns="True"
OnItemDataBound="Datagrid1_OnItemDataBound"/>
Private Sub DataGrid1_ItemDataBound(s As Object, e As DatagridItemEventArgs)
e.Item.Cells(1).Visible = False
End Sub
Graeme
<dl> wrote in message news:%...
> Hi
> Where is the proper place to hide a column dynamically? I tried putting
> this line in ItemDataBound,
>
> myDataGrid.Columns[2].Visible = false;
>
> but is giving me index out of range error! Am I putting this in a wrong
> place (ItemDataBound)?
>
> Any idea?
> TIA
>
> --
>
>
>