How to set a Datagrid Column to invisible when that Column is an AutoGeneratedColumn

Platform: ASP.NET| Category: DataGrid

In the DataGrid’s declaration, add the following code in OnItemDataBound event
VB.NET


Dim dv As DataView = DataGrid1.DataSource ’Bind you DataGrid1 in Page_Load to DataView
Dim dc As DataColumnCollection = dv.Table.Columns
e.Item.Cells(dc.IndexOf(dc('field_name))).Visible = false

C#


DataView dv = DataGrid1.DataSource ;//Bind you DataGrid1 in Page_Load to DataView
DataColumnCollection dc = dv.Table.Columns;
e.Item.Cells[dc.IndexOf(dc['field_name'])].Visible = false;

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.