you'll have to throw the exception so add a handler to AppDomain.UnhandledException like I mentioned before. I recommend you also create a custom exception class that derives from ApplicationException (typically used for custom exceptions to give them a common, application-based base class) that you throw from the DataTable.RowChanging event handler. This way, you can easily just catch this exception in the handler for the AppDomain.UnhandledException event and handle appropriately, which is better than throwing such a oft-used exception and trying to determine where it came from and why it was thrown.
你可以在RowChanging事件中调用一个方法来添加行。而截获也是在这个方法里。不知可以不
throw myException;//throw exception here
}
catch(MyException e)
{
//do something here;
}
……
throw myException
}
catch(MyException e)
{
Response.write(e);
}
在RowChanging事件里处理了异常以后,异常就没有了,就不会阻止DataTable继续添加该行数据。
真正调用它的是在
OnRowChanged这个函数中。我觉得你可以重写OnRowChanged这个虚函数,在里面捕捉你的异常。最后在调用一下基类的得OnRowChanged。
如果通过,则oldRowIndex=newRowIndex,否则手动选择oldRow