The datasource for my RadGrid is a simple datatable. The grid has a GridClientDeleteColumn object. When I click delete, I want to remove the row from the grid and delete the row from the datatable the grid is bound to via NeedDataSource. I'm using RadAjaxManager.
To do all this, I call a javascript function via OnRowDeleting. From there I get the row's unique key via eventArgs.getDataKeyValue and pass it to a server-side function that has a WebMethod attribute. It deletes the row from the datatable. (If this is not the simplest/best way, then please advise.)
Anyway, it works great!... unless I delete the bottom row in the grid. Then when the grid refreshes, I get this error...
JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Specified argument was out of the range of valid values.
Parameter name: ItemHierarchicalIndex
It's not a particular row, but always the bottom row. I know this because I can sort the row by various columns, but only when I delete the bottom row and it refreshes do I get the error.
While trying to debug, on a whim, I put this line first in my javascript function that OnRowDeleting calls...
eventArgs.set_cancel(true);
Now when I delete the bottom row, as expected, it does not remove the row from the grid. However, when the grid is refreshed, I don't get the error and the row is gone because it was indeed deleted from the table on server-side.
What's the problem? Why does everything work unless it's the bottom row? And again, if there's a simpler/better way in general to remove the grid row and delete it from the datatable, then please advise.