Bulk Edit Grid View
Nicolas Galler | November 23, 2007As planned I have implemented the bulk edit mode for the grid view.
This is very inspired from this post from Matt Dotson, in fact the only difference is that it will save automatically on every page refresh instead of relying on a save button – this allows it to work in conjunction with paging and also not be affected when postbacks occur from other controls.
Compared to his article I had to implement these additional event handlers:
- Grid.DataBinding: I call SaveGrid here to ensure the data gets saved before it is refreshed. This needs to be protected with a lock because UpdateRow may cause databinding to be performed as well
- Grid.RowUpdated: set the KeepInEditMode to true – this prevents the grid from trying to rebind (so this should remove the lock requirement from the previous handler, but I kept it in to be on the safe side)
- Grid.RowInitializing: this is an event I added to the grid, because otherwise there is no way to slip something into InitializeRow without actually deriving from the grid (my strategy with the grid view is to define feature “mix-in” modules that can be added to a stock (or in this case, “almost” stock) grid view. The problem if you derive from GridView every time is it becomes hard to combine those features… i.e. a classic problem of inheritance vs composition. Unfortunate that ASP.NET favors the former, but that is for another post)
- Grid.PageIndexChanging: call SaveGrid here otherwise the data will be muffed when the user changes pages
The SaveGrid implementation is a bit simpler, since my DataSource control is completely disconnected so I can afford to call Update pretty often… for this reason I did not bother with keeping a “dirtyRows” list and instead update every single row in the datagrid.
In the end, it gives a pretty transparent experience to the user, something like this:






Is the revised code available?
No problem, I posted the code here, hope this can be of help!
The link for the code seems to be broken?
Fixed it – thanks for the heads up!
Hi, I was looking for a solution to have bulk edit gridview without having it to Inherit from Gridview control directly and your solution seems to fit the profile.
Unfortunately I am pretty rusty when it comes to front end development as I have been doing backend work for past 5 years.
I have an existing code that I have to modify to implement bulk edit functionality, This code uses a User Control that in itself has a GridView control among other things. Some of the events and methods of this GridView are then overridden in order to implement custom formatting of rows, etc…
I’m not sure how to implement your solution in my case.
As I understood, the first part of your code is a standard class that inherits from GridView and I should put it in the App_Code folder. Now, the rest is a bit more confusing to me, where do I reference the bulk edit user control, do I replace my existing control with it?
In the aspx code in my case where it references the custom use control I cannot see the BulkEditGridViewMixin, how can I reference it properly.
I also cannot define the bound fields at the aspx level, as they are created at run time from an sqldatasource for formating and for creation of some hidden fields.
Lastly, for the update of the data (push back) I need to utilize a business component/module already in place, so I was planning on Overriding the Grid_OnRowUpdating and canceling the sql’s default update command and instead calling my own method to validate and push data back.
I know this is a lot of info and probably too confusing to understand, but if you have any suggestions they will be appreciated!
Thanks
Alex