After much searching here at the ASP.NET forum I found only partial solutions to removing Datagrid columns at runtime. The most common solution would remove the column, causing a frame shift, or leaving the Column Header intact with the cells below it inivisible.
The following solution worked well and I thought I would post this for those who might be trying to accomplish the same task but having difficulties.
To remove both the header and underlying column of your Datagrid at runtime (set to Autogenerate=false) use the following code in the ItemDataBound event handle:
The Datagrid used the nominal <asp:BoundColumn.. format.
The following solution worked well and I thought I would post this for those who might be trying to accomplish the same task but having difficulties.
To remove both the header and underlying column of your Datagrid at runtime (set to Autogenerate=false) use the following code in the ItemDataBound event handle:
Code:
Sub dgChemData_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
If yourcondtion Then
e.Item.Cells.Remove(e.Item.Cells(0))
End If
End If
..followed by turning off the Header for the same column:
If e.Item.ItemType = ListItemType.Header
e.Item.Cells.Remove(e.Item.Cells(0))
End If
End Sub
The Datagrid used the nominal <asp:BoundColumn.. format.