For i = 0 To dgvContract.Rows.Count - 1
Dim chkRow As CheckBox = dgvContract.Rows(i).FindControl("chkCRow")
If chkRow.Checked = True Then
strSQL = "DELETE FROM Contract WHERE Contr_ID = '" & dgvContract.DataKeys(i).Value & "'"
'Me.txtSearch.Text = strSQL
cmd = New SqlCommand(strSQL, conn)
cmd.ExecuteNonQuery()
strSQL = "DELETE FROM Payment where Contr_ID = '" & dgvContract.DataKeys(i).Value & "'"
cmd = New SqlCommand(strSQL, conn)
cmd.ExecuteNonQuery()
ElseIf chkRow.Checked = False Then
ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "Error", "<script language=javascript>alert('กรุณาทำเครื่องหมายหน้าสัญญาที่คุณต้องการลบก่อน');</script>", False)
End If
Next