RSS 2.0
# Wednesday, September 20, 2006

When you make columns invisible in a GridView-control the values in those columns are ignored when doing an update. If the update function, stored proc, or whatever expects these values (particularly when you use CollisionDetection="CompareAllValues"), the update will fail.

The solution:
- Add the names of the invisible columns to the DataKeyNames-properties separated by a comma, so the values are available.
- Create an event handler for the GridView.RowUpdating and add the code below. This copies all "key" values to the old and new values so the update will work.

IDictionaryEnumerator restoreOldValues = e.Keys.GetEnumerator();
while (restoreOldValues.MoveNext())

   e.OldValues.Add(restoreOldValues.Key.ToString(), restoreOldValues.Value.ToString());
   e.NewValues.Add(restoreOldValues.Key.ToString(), restoreOldValues.Value.ToString());
}

Wednesday, September 20, 2006 5:11:11 PM (W. Europe Daylight Time, UTC+02:00)  #    Comments [0] -
ASP.NET | English
Sign In

Archive
<September 2006>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
About
This is the blog of Michiel van Otegem, a Senior Software Architect with Sogeti Netherlands, and author of several books and numerous articles on (ASP).NET, XML, and related technologies.
Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Michiel van Otegem
All Content © 2012, Michiel van Otegem
DasBlog theme 'Business' created by Christoph De Baene (delarou)