Datagrid delete button in asp net - Programmers Heaven

Howdy, Stranger!

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


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Datagrid delete button in asp net

ZpixelZpixel Posts: 28Member
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.


  • johnkingsley06johnkingsley06 Posts: 6Member
    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.