Hi @Hutty , Welcome to Microsoft Q&A,
The error you're encountering is due to trying to cast a control that is not a TextBox into a TextBox. In your GridView, some cells contain CheckBox controls instead of TextBox controls. You need to check the type of control in each cell before attempting to cast it.
Dim columnValue As String
For Each cell As TableCell In row.Cells
For Each ctrl As Control In cell.Controls
If TypeOf ctrl Is TextBox Then
columnValue = CType(ctrl, TextBox).Text
ElseIf TypeOf ctrl Is CheckBox Then
columnValue = CType(ctrl, CheckBox).Checked.ToString()
End If
Next
Next
Dim whereClause As String = String.Format(" WHERE {0} = '{1}'", CType(GV1.HeaderRow.Cells(1).Controls(0), LinkButton).Text, GetControlValue(row.Cells(1).Controls(0)))
Private Function GetControlValue(control As Control) As String
If TypeOf control Is TextBox Then
Return CType(control, TextBox).Text
ElseIf TypeOf control Is CheckBox Then
Return CType(control, CheckBox).Checked.ToString()
Else
Return String.Empty
End If
End Function
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.