When the ImageDelete button is ImageDelete , the RowCommand event RowCommand . However, in the event handler for RowCommand you do not delete anything. On the other hand, the RowDeleting event RowDeleting not occur at all, since the correct command for this event is Delete , not cmdDelete .
I see two possible fixes for this. First move the code for the delete operation to the RowCommand event RowCommand :
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand If e.CommandName = "cmdDelete" Then Dim ID As Integer = Convert.ToInt32(e.CommandArgument) con.Open() Dim cmd As New SqlCommand("delete from [tblUser] where [ID] =@ID ", con) cmd.Parameters.AddWithValue("@ID", ID) cmd.ExecuteNonQuery() con.Close() End If End Sub
Second, change the command name and use the already implemented RowDeleting handler:
<asp:ImageButton ID="ImageDelete" ImageUrl="" runat="server" CommandName="Delete" CommandArgument='<%# Eval("ID") %>' />
source share