Hiding an asp.net Gridview column while allowing update and Insert
Sometimes you want to put a value into a gridview column for updates and inserts, but you don’t want it shown. If you set the column to invisible, it will not be included in Updates or Inserts defined in the SQLDataSource. The solution is to set it to Display:None through CSS. Here is how to do it.
First define the style, either in your stylesheet, or in your HTM header:
<style type=”text/css”>
.Hide
{
display: none;
}
</style>
The apply the style to the column in the Gridview:
<asp:BoundField DataField=”your_field” HeaderText=”your_field” SortExpression=”your_field”>
<ItemStyle CssClass=”Hide” />
<HeaderStyle CssClass=”Hide” />
</asp:BoundField>
That’s all it takes!