コードビハインドから検証しようとしているグリッドビューがあります。この場合、レコードの削除を確認します。私の削除方法は、検証を追加するまでは正常に機能します。検証を実装しても、削除は実行されません。
明確にするために、RowDataBound検証を追加するまで、削除メソッドは正しく機能します。
<asp:CommandField
ButtonType="Image"
ShowEditButton="true"
ShowDeleteButton="true"
ShowCancelButton="true"
EditImageUrl="~/Images/edit-icon.gif"
UpdateImageUrl="~/Images/save-icon.png"
CancelImageUrl="~/Images/cancel-icon.png"
DeleteImageUrl="~/Images/delete-icon.png"
/>
関連する方法は次のとおりです。
Protected Sub usersGrid_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
For Each control As Control In e.Row.Cells(0).Controls
Dim DeleteButton As ImageButton = TryCast(control, ImageButton)
If DeleteButton IsNot Nothing AndAlso DeleteButton.CommandName = "Delete" Then
DeleteButton.OnClientClick = "return(confirm('Are you sure you want to delete this user?\nThis cannot be undone!'))"
End If
Next
End Sub
Protected Sub usersGrid_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
Dim userID As Integer = DirectCast(usersGrid.DataKeys(e.RowIndex).Value, Integer)
usersGrid_Delete(userID)
BindData()
End Sub
Protected Sub usersGrid_Delete(ByVal userID As Integer)
Dim con As New SqlConnection(connectionString)
Dim cmd As New SqlCommand("MAINT_DIST_DELETE_USER", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@userID", userID)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch Ex As Exception
Throw Ex
Finally
con.Close()
End Try
End Sub