Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
400
WebGrid DataChanged property
posted

I'm attempting to use the Row.DataChanged property to control updates to our database, but I must not full understand how it works.  Any suggestions would be appreciated.

We bind a dataset to a grid and display it.  The user is allowed to make changes (modify, add, delete).  When the user has finished, they click a Save button.  The Save button server-side implementation does the actual database updates.  We don't want to update the database until Save is clicked.

The Save implementation iterates over Grid.Rows looking at DataChanged for each row.  This works fine for Unchanged, Added and Modified rows.  However, Deleted rows are gone from Grid.Rows so we can't capture those changes.  The documentation for DataChanged seems to indicate that all four row states should be possible.

What am I missing?  Do Deleted rows only show up for certain types of data sources?  Do Deleted rows ever show up?  I'd really like to avoid caching the data to determine what was deleted, but that seems like the next step.  Any other suggestions?

Thanks,

DaveL

  • 478
    Offline posted

    I would suggest that probably the best way to do this would be to  handle either the DeleteRow or DeleteRowBatch events. You could either do the deletions directly in those event handlers, or use them to build a list of keys to do your deletion in the Save button click handler.

     

    Iterating over the entire Rows collection probably isn't the most efficient way of handling inserts and updates either...

  • 168
    Offline posted

    Have a look at the DeleteRowBatch server-side event. This is fired for every row deleted when the grid is submitted.

    There is also an UpdateRowBatch event which fires for every row added/updated.

    Note there is a potential problem with this if you add a row and then delete it in the grid and then save - the UpdateRowBatch event is fired for the row added event though it was deleted.