0

Coding Platform: ASP.NET 4.0

I am binding a GridView with LinqDataSource with AutoDelete functionality enabled.
GridView is bound to the Products Table.
I have a Products Table and a Category Table with an association on CategoryID.
If I try to delete a Category that is referred in the Products Table I cannot do that.
Its is totally acceptable, but I want the end user to be notified with some error message.
Where to catch this error message?

naveen
  • 53,448
  • 46
  • 161
  • 251

2 Answers2

0

put datacontext.submitchange() in try cacth as like below

try { datacontext.submitchange(); } catch() {

}

slash shogdhe
  • 3,943
  • 6
  • 27
  • 46
0

Ended up using OnDeleting event of the LinqDataSource

    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);
        }
    }
naveen
  • 53,448
  • 46
  • 161
  • 251