Reputation: 7621
I have a GridView and a SqlDataSource, which I have set to automatically generate Delete/Insert/Update statements. I then just enabled Deleting on the GridView, and usually away I'd go. For some reason though, the row is not being deleted - the page is posting back but the row is still there. When Delete is clicked, RowDeleting does fire though.
What possible causes could this be?
Edit: SELECT command:
SELECT id, templatename, CASE WHEN type = 'W' THEN 'Weekly' WHEN type = 'M' THEN 'Monthly' WHEN type = 'Q' THEN 'Quarterly' WHEN type = 'S' THEN 'Six-monthly' WHEN type = 'A' THEN 'Anually' END AS TypeText, CASE WHEN invorcred = 'I' THEN 'Invoice' WHEN invorcred = 'C' THEN 'Credit' END AS 'InvOrCredText', nextinvdate, lastinvdate FROM InvoiceTemplates WHERE (sageaccount = @sageaccount)
Upvotes: 0
Views: 742
Reputation: 3297
Try to write in the RowDeleting event instead of auto generated, maybe because you need to get the id of the row you want to delete (Where clause)
Example: Label13 is Hidden, I get it from select statement but I don't show it the user. VB.NET:
Protected Sub gvAddresses_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvAddresses.RowDeleting
Dim selectedAddessId As Label = gvAddresses.Rows(e.RowIndex).FindControl("Label13")
SqlDataSource.DeleteParameters("add_id").DefaultValue = selectedAddessId.Text
SqlDataSource.Delete()
End Sub
C#
protected void gvAddresses_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
{
//Get the address Id to delete the selected address only
Label selectedAddessId = gvAddresses.Rows(e.RowIndex).FindControl("Label13");
SqlDataSource.DeleteParameters("add_id").DefaultValue = selectedAddessId.Text;
SqlDataSource.Delete();
}
Upvotes: 2
Reputation: 18797
Do you return data from multiple tables in database? If your sqldatasource's select command, selects data from more than one table, I think the delete command would not work.
Upvotes: 0
Reputation: 517
Try see which SQL statement has been executed on DB. (You can use for this purpose the "SQL Server Profiler" utility)
Upvotes: 0
Reputation:
Try converting the delete column to a template field. There is a known bug for the delete command in combination with imagebuttons.
Upvotes: 0