I\'m using GridView
along with SqlDataSource
, for selecting, updating and deleting,
and Detail
Add the DeleteCommand
to your SqlDataSource
:
DeleteCommand="Delete from yourTable WHERE (ID = @ID)"
Like this:
<asp:SqlDataSource runat="server" DeleteCommand="Delete from yourTable WHERE (ID = @ID)">
<DeleteParameters>
<asp:Parameter Name="ID"></asp:Parameter>
</DeleteParameters>
</asp:SqlDataSource>
EDIT: To make ASP.NET generate the DELETE
command automatically for you without any code do the following steps:
SqlDataSource
, click Configure Data Source.Select DELETE Tab and then click on the Query Builder, Select your table and then build your query by helping the Query Builder window. Your query should be look like this finally:
Delete from yourTable WHERE (ID = @ID)
And finally click Next And Finish.