Write For Us

About GridView Hidden Column

When a Gridview column's visibility is set to False, then the Grid does not bind data to the column, and thus when you try to retrieve data from the hidden column in the code-behind, it either blows up or returns an empty string.


Maybe you don't need it

It's likely that you don't need the column, at all. If it's not used in your Update statement, Insert statement, or in the code behind, then just remove it. If you are using Table Adapters, then remove the column out of the TableAdapter.

Need it in the Code Behind

If you really need it, don't hide the column, remove it as a column,

and then add the column name to the DataKeyNames Collection of the Gridview.

You can now access these columns in the special DataKey collection of the Gridview, i.e. Gridview1.Datakeys(iRow).Values

You need to pass this back to SQL

If you actually need to pass this back to SQL (via table adapters) then you have to configure the table adapters to accept the column.

All columns in the DataKeyNames get the "Original_" prefix as defined in the ods property


Modify the Update Parameter Collection

Such that the hidden column expects the prefix (just like your Primary Key column was done automatically)

Lastly edit the actual T-SQL to expect the parameter with the prefix.

This tutorial is written by Jeremy Libertor

Tutorial toolbar:  Tell A Friend  |  Add to favorites  |  Feedback  |