How can I update only ticked records from the GridView?
Please help I would want to update only ticked records from the GridView by referring to the GridView cells that have the updated records please.
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For Each di As GridViewRow In GvStudentMarks.Rows
Dim chkBx As CheckBox = DirectCast(di.FindControl("checkbox1"), CheckBox)
If chkBx IsNot Nothing AndAlso chkBx.Checked Then
Dim act As String = di.Cells(2).Controls.OfType(Of TextBox)().FirstOrDefault().Text
' put your code here
Dim eng As Integer = DirectCast(di.FindControl("txteng"), TextBox).Text
' Dim eng As Integer = Convert.ToInt32(TryCast(FindControl("lblEng"), Label).Text)
Dim maths As Integer = DirectCast(di.FindControl("txtmaths"), TextBox).Text
Dim cmd As New SqlCommand()
cmd = New SqlCommand("UPDATE students SET eng = @y14x1,username= @usr WHERE AdmNo = @AdmNo")
cmd.Parameters.AddWithValue("@y14x1", di.Cells(2).Controls.OfType(Of TextBox)().FirstOrDefault().Text)
' cmd.Parameters.AddWithValue("@usr", entryuser)
cmd.Parameters.AddWithValue("@AdmNo", GvStudentMarks.DataKeys(di.RowIndex).Value)
Me.ExecuteQuery(cmd, "UPDATE")
' MsgBox("gooog")
End If
Next
End Sub