I’m using a list of objects as the data source of my GridView and when I set columns to not be visible the updates fail because the value of those columns is changed to null (and the column doesn’t allow nulls). The values do exist when the columns are visible but I really don’t want to display these columns because, for the most part, they are ID columns that the user doesn’t really need to see.
EDIT: I’ve tried the hidden field option but it still sets the value to null. I’ve looked at the page source and the hidden field exists with the appropriate value…
I found this solution to simulate hidden columns in .Net 2.0:
Implement the GridView.RowCreated event.
Here’s the link: http://www.beansoftware.com/ASP.NET-Tutorials/GridView-Hidden-Column.aspx
I guess in 2.0 when a column is not visible the databinding fails for that column but this method hides after the link has been established so it tricks the system (?).