dimanche 26 février 2017

I want to update category of checked row in grid view, but it is giving the following error

Value of type 'System.Web.UI.Control' cannot be converted to 'System.Windows.Forms.CheckBox'

Here is the code:

Protected Sub btnMigrate_Click(sender As Object, e As EventArgs) Handles btnMigrate.Click
        Dim i As Integer
    For Each row As GridViewRow In GridView1.Rows
        If row.RowType = DataControlRowType.DataRow Then
                'If GridView1.GetType().Name = "chkbox" Then
                Dim chkRow As CheckBox = TryCast(row.Cells(5).FindControl("chkbox"), CheckBox)

            If chkRow.Checked Then
                Dim compid As String = row.Cells(0).Text
                Dim con As New SqlConnection("Data Source=DESKTOP-aiu042b;Initial Catalog=Municipal Corporation;Integrated Security=True")
                con.Open()
                Dim str As String = "update Complaint_info set c_category=@c where Category=@ct and complaint_id=@cid"
                Dim cmd As New SqlCommand(str, con)
                cmd.Parameters.AddWithValue("@c", txtCategory.Text)
                cmd.Parameters.AddWithValue("@ct", "OTHER")
                cmd.Parameters.AddWithValue("@cid", compid)
                i = cmd.ExecuteNonQuery
            End If
            ' End If
        End If
    Next

    If i > 1 Then
        MessageBox.Show("Records migrated to category " + txtCategory.Text)
    End If

End Sub




Aucun commentaire:

Enregistrer un commentaire