我有一个连接到 ObjectDatasource 的 Select 方法,该方法可能会引发异常,但我不知道如何处理它!
问题是我无法控制它。当页面呈现时,ObjectDatasource 直接调用 select 方法,并直接抛出未处理的异常。
另一方面,如果有问题,我不想让它返回空集合,因为集合可能是空的,没有问题。
那么,哪里可以处理异常呢?
还有其他选择吗?
查看 ObjectDataSource 上的 eventargs。应该有一个 e.Exception 和 e.Results,您可以查询选择的成功/错误。
protected void MyOds_Selected (object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
// handle exception here.
...
//tell the ObjectDatasource that the exception is handled
//and don't rethrow it.
e.ExceptionHandled = true;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)