In our application, we are adding a row to a datatable. I would like to validate the row before it is added to the table, and if the data doesn’t meet business requirements, the row does not get added.
I would think RowChanging even is where I need to add validation code. However, how do I prevent the row from being added to the DataTable?
In our application, we are adding a row to a datatable. I would like
Share
I think the only way you can stop a row from being added in the
RowChangingevent handler is to throw an Exception:You’d obviously have to catch this exception and handle it gracefully.
A better approach would be to do your validation in the UI before attempting to add the new
DataRow.