0

编码平台:ASP.NET 4.0

我正在将 GridView 与 LinqDataSource 绑定并启用 AutoDelete 功能。
GridView 绑定到 Products 表。
我有一个产品表和一个与 CategoryID 关联的类别表。
如果我尝试删除产品表中引用的类别,我将无法这样做。
这是完全可以接受的,但我希望最终用户收到一些错误消息的通知。
在哪里捕获此错误消息?

4

2 回答 2

0

将 datacontext.submitchange() 放入 try cacth,如下所示

尝试 { datacontext.submitchange(); } 抓住() {

}

于 2010-12-24T09:55:09.860 回答
0

结束了使用 LinqDataSource 的 OnDeleting 事件

    protected void LinqDataSource1_Deleting(object sender, LinqDataSourceDeleteEventArgs e)
    {
        try
        {
            Categories category = (Categories)e.OriginalObject;
            if (helper.IsCategoryPresentInProductsTable(category.CategoryID))
            {
                e.Cancel = true;
                StatusLabel.Text = String.Format("{0} is referred in the products table. Delete aborted!",
                    category.CategoryName);
                StatusLabel.Visible = true;
            }
        }
        catch (Exception err)
        {
            Elmah.ErrorSignal.FromCurrentContext().Raise(err);
        }
    }
于 2010-12-28T07:01:28.373 回答