Possible causes for automatically generated Delete command for GridView not working
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 do开发者_运维问答es 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)
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();
}
Try converting the delete column to a template field. There is a known bug for the delete command in combination with imagebuttons.
Try see which SQL statement has been executed on DB. (You can use for this purpose the "SQL Server Profiler" utility)
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.
精彩评论