Hello,
uwgEmployees.DisplayLayout.Rows.Remove(row)
Everything works fine except when a user does a group by on the grid and then tries to delete selected rows. In this event the call to remove throws an exception. What is the correct method of removing selected rows from the grid?
Thanks!
Vince, Thanks for your suggestion with using the JavaScript approach to remove selected rows. Unfortunately it does not work in our scenario as only the selected rows that pass a certain validation(server side) needs to be removed.
Do you have any pointers on where I can start with finding the selected rows. For a simple test, I did a group by and was able to remove the first row of the first group by using
grid.DisplayLayout.Rows[0].Rows.Remove(row)
I am not sure how to go about traversing the row hierarchy when there are multiple groups.
When you're using Outlook group-by on WebGrid, the rows in the grid's Rows collection (or in DisplayLayout.Rows) are your group-by rows. These rows can't be removed in this fashion.
Theoretically, you'd need to find each row you want to delete under the Rows collection of the appropriate group-by row. This isn't difficult, but also isn't trivial.
However, there might be a better way to accomplish what you're after in client-side code. Assuming that "grid" is a reference to a WebGrid on your page, the following JavaScript will delete all selected rows from the grid:
grid.deleteSelectedRows();