Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Soft Gallery
    • autosvnbackup.sh
    • VBScript Snippets
  • Contact Me
  • Welcome

Bulk Edit Grid View

Nicolas Galler | November 23, 2007

As 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:

  1. 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
  2. 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)
  3. 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)
  4. 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:

Categories
Programming
Comments rss
Comments rss
Trackback
Trackback

« Slx 72 Web Windows Authentication Explained Unit Testing SLX »

5 Responses to “Bulk Edit Grid View”

  1. Anonymous says:
    December 24, 2007 at 1:35 pm

    Is the revised code available?

  2. Nicolas Galler says:
    December 24, 2007 at 3:17 pm

    No problem, I posted the code here, hope this can be of help!

  3. Travis says:
    December 9, 2009 at 8:51 am

    The link for the code seems to be broken?

  4. Nicolas Galler says:
    December 11, 2009 at 10:39 am

    Fixed it – thanks for the heads up!

  5. Alex says:
    May 25, 2010 at 9:44 am

    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

Leave a Reply

Click here to cancel reply.

Categories

  • Experiments (4)
  • Interesting (1)
  • MSCRM (1)
  • Programming (60)
  • Rant (3)
  • Saleslogix (34)
  • Tricks (8)
  • Uncategorized (30)

Post History

  • 2010
    • January (3)
    • March (3)
    • April (2)
    • August (2)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox