Gridview's CellEditorInitialize() and ParseValue() are called multiple times (for the same field) while processing the update after editing/inserting a row.
- It makes no sense at all to fire CellEditorInitialize() when doing an update after editing. The editor form is closing and the editors will not be seen again! Furthermore, this event is fired twice on each field before the update completes.
- The ParseValue() event fires THREE times for each field during the update. This is not only grossly inefficient but is highly destructive. Since the purpose of the event is most likely to alter the values coming back from the editors, possibly based on those very editied values ( e.Value = DoSomethingWith(e.Value) ) the result is that the desired editor value is destroyed by being operated on multiple times.
Steps to Reproduce:
Launch the attached test project - Set up a SQLDatasource and connect it to your favorite table, set up for selects, updates and inserts.
- Drop a GridView on the page, connect it to the datasource, enable it for edits and inserts, take all other default settings, let it load up all the colunms from the datasource.
- Add even handlers for CellEditorInitialize() and ParseValue().
- Place breakpoints on these two event handlers.
- Run the page, edit a row, and click Update. Observe when and how many times the events are fired.
Actual Results:
CellEditorInitialize() fires twice for each field during the update.
ParseValue() fires three times for each field during the update.
In each case, the even fires once for each field in the correct sequence before repeating this sequence.
CellEditorInitialize (2:55:14): CategoryName
CellEditorInitialize (2:55:14): Description
CellEditorInitialize (2:55:21): CategoryName
CellEditorInitialize (2:55:21): Description
ParseValue (2:55:21): CategoryName=Meat/Poultry
ParseValue (2:55:21): Description=Prepared meats
CellEditorInitialize (2:55:21): CategoryName
CellEditorInitialize (2:55:21): Description
ParseValue (2:55:21): CategoryName=Meat/Poultry
ParseValue (2:55:21): Description=Prepared meats
ParseValue (2:55:21): CategoryName=Meat/Poultry
ParseValue (2:55:21): Description=Prepared meats
Expected Results:
CellEditorInitialize() should fire once per field on the start of the edit, and never fire on an update. ParseValue should fire exactly once for each field.
IMPORTANT NOTE: Before the changes made to resolve this issue the Grid reset its hierarchy before calling its OnCallback server-side event. As a result, you can refer to its elements and templates in this event handler without re-binding. Now, the Grid resets its hierarchy and it's necessary to explicitly apply data changes to controls by calling the DataBind() method. This may cause some issues in the existing applications. For example, check this report: populate combobox on fly in gridview
Thanks,
Serge