I have a client-side script that deletes a row in my grid. I handle the following DeleteRow event with a server-side method. Is it possible to cancel the deleting of the row, and bring the row back in the grid server-side, without reloading the grid completely? I've tried setting e.Cancel = true; but that doesn't do the trick.
That sounds very odd, then, and I'm not sure what's going on. It'll probably take deeper investigation of the code you're using to figure out what's happening (and not happening) and why.
I suggest you submit a support request so that a Developer Support Engineer can help you in more detail. If you can, please create an isolated sample application that we can run and debug that demonstrates this behavior. If you need to connect to a database, I suggest you either use Northwind in SQL Server or an Access database file that you include with the sample.
No, I'm not using AJAX... so it's strange that the grid doesn't update when I do DataBind() :(
If you're in server-side code (which you are if you're handling the UpdateGrid event), then you're already either in the middle of a postback, or you're in the middle of an AJAX callback. In the latter case, I don't know how to force the page to perform a complete postback by using server-side code.
Thanks for your response. I am now handling the UpdateGrid event as you suggested but when I do grid.DataBind() in the eventhandler, the grid is not updated on the page. Is DataBind() not forcing a post-back or how can I do that?
I don't believe that you can cancel row deletion in server side code without essentially re-binding the grid.
The way I'd do this is to simply not delete the row from my underlying data source in the grid's DeleteRow event under the appropriate circumstances. I'd also handle the grid's UpdateGrid event (raised once per postback after all add/update/delete events are processed) and re-bind my grid to the data source. This would account for all the changes that I didn't undo, but wouldn't apply this row deletion since I never deleted it from the data source.
I don't believe that this approach will work if you're using the grid's built-in AJAX functionality, however. This is because the grid only passes back and forth information about the individual row that was affected, and since the row was already deleted in the client, it wouldn't be recreated.