Ondrej
Ondrej

Reputation: 1660

Extending delete method of GridView

I have a page with GridView pulling some data from a SQL Server database via Linq-to-SQL.

I made use of the automatically-generated buttons for deleting. However, in order for the delete command to work properly, I need to somehow make sure that one table in relation with those records I want to delete, is also modified (the related record in it is also looked up and deleted).

Whats the easiest way to do this?

Thanks, Ondrej

Upvotes: 0

Views: 210

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460208

Define a foreign-key constraint with cascade delete.

Delete Rule

Specify what happens if a user tries to delete a row with data that is involved in a foreign key relationship:

  • No Action An error message tells the user that the deletion is not allowed and the DELETE is rolled back.
  • Cascade Deletes all rows containing data involved in the foreign key relationship.
  • Set Null Sets the value to null if all foreign key columns for the table can accept null values.

Upvotes: 2

Related Questions