0

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)

4 Answers 4

2

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();
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try converting the delete column to a template field. There is a known bug for the delete command in combination with imagebuttons.

1 Comment

I've tried that and sadly still nothing. Also I believe it's just using a LinkButton
0

Try see which SQL statement has been executed on DB. (You can use for this purpose the "SQL Server Profiler" utility)

Comments

0

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.

2 Comments

No, but that's a point. Something I am always changing is the SELECT command, but it's all from one table. I'll update the post with this.
Tried with just the bog standard select generated and still doesn't work :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.