protected void btnDelete_Click(object sender, EventArgs e) { try { AddressBookRepository context = new AddressBookRepository(); context.DeletePersonByID(1); GetPeople(); lblError.Text = "Contact deleted."; } catch (OptimisticConcurrencyException) { lblError.Text = "There was an error while deleting record from database. The record you attempted to delete was modified by another " + "user after you got the original value. The delete operation was canceled."; } catch (ArgumentNullException) { lblError.Text = "There was an error while deleting record from database. Make sure that user exist."; } catch (Exception) { lblError.Text = "There was an error while deleting record from database. Please try again."; } }
protected void contactsGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { // int index = e.RowIndex; // index of the row to delete -> where Delete button clicked int personID = Convert.ToInt32(contactsGridView.DataKeys[e.RowIndex].Value); try { AddressBookRepository context = new AddressBookRepository(); context.DeletePersonByID(personID); GetPeople(); lblError.Text = "Contact " + " " + e.Values["FirstName"] + " " + e.Values["LastName"] + " deleted!"; } catch (OptimisticConcurrencyException) { lblError.Text = "There was an error while deleting record from database. The record you attempted to delete was modified by another " + "user after you got the original value. The delete operation was canceled."; } catch (ArgumentNullException) { lblError.Text = "An error occured while deleting contact. Make sure that contact exists."; } catch (Exception) { lblError.Text = "An error occured while deleting contact. Please try again."; } }