Datagrid delete button in asp net

after adding a delete button to a datagrid in a asp net website, i want to know how to enable deleting a record of database table using this button. this is the error message after clicking that button:

Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified.


how can i specify delete command? is this a good way to delete a database record? what do you usually do? i prefer old style tables and links. like what i do in php.


  • First You have to specify 'Delete Command' in your 'SqlDataSource1' like the following:
    DeleteCommand = "Delete .. from Table name"..
    But Actually speaking, this is not the best practice to play the deletion.
    Because when you deploy your project, Any user can view the connection settings thorugh 'ViewSource'-(By RIght-Clicking in page)
    But that is not recommended.
    Also in all sites, Deletion means not completely Data deletion. Actually they change the Indicator from Active to InActive and display the Active data to User.
    So, Automatically the Inactive data wont be displayed. But it will be kept in database.
    What People usually do is, In the Clicking event, They specify the connection settings and write code to update the data(Here Data to be deleted) from Active to Inactive
    and display the Active data
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion