Sqldatasource updating event args
The Grid View control stores these key field values in the control state.
If these values contain sensitive information, it is strongly recommended that you enable view-state encryption by setting the View State Encryption Mode property to property for the automatic updating and deleting features of the Grid View control to work.
While error checking my update command for this setup I noticed something funny..of :( Any column from my database which was listed in the Data Key Names would not get the new value posted back when the update was performed.
All other columns/parameters worked fine and was updated.
First let's start from Grid View's On Bubble Event: protected override bool On Bubble Event(object source, Event Args e) private bool Handle Event(Event Args e, bool causes Validation, string validation Group) We can see if the command name is "Update" it will call Handle Update method.
private void Handle Update(Grid View Row row, int row Index, bool causes Validation) Please focus on the bold one. Since you're using Sql Data Source it's Update method will be called here: public int Update(IDictionary keys, IDictionary values, IDictionary old Values) protected override int Execute Update(IDictionary keys, IDictionary values, IDictionary old Values) Pay attention to the bold lines.
This will not work if you want the values hidden in control state though.
Best regards Frode Dragland Hi: Thanks for your clarification.
You can set a breakpoint in Row Updating event handler of Grid View. Problem is still there why New Value is not accepted by the Sql Data Source. We can see values (if we track back we see it's New Values) are added to parameters earlier than the keys. Update Parameters, keys, null, old Values Parameter Format String); keys is added to parameters later than values therefore it'll OVERWRITE that new value which resulted in the issue you mentioned.
the variable e is just the same as following bold one. protected void Grid View3_Row Updating(object sender, Grid View Update Event Args e) The result is: e. Before we track further let's set a breakpoint in Sql Data Source's Updating event handler: protected void Sql Data Source1_Updating(object sender, Sql Data Source Command Event Args e) So the problem is, between these two events there're some code that will modify(just a guess for now) the new value. Let's see what's the Add Parameters method: private void Add Parameters(Db Command command, Parameter Collection reference, IDictionary parameters, IDictionary exclusion List, string old Values Parameter Format String) I've marked the logic if you're not using Old Values Parameter Format String. It's a long track but fortunately we finally find the reason for this behavior.
If I take those extra column names out of the Data Key Names property, it works again...
Those extra columns names are not primary keys in the database in any way.