syntax error why

 Protected Sub CheckBox2_CheckedChanged1(sender As Object, e As EventArgs)
        For Each r As GridViewRow In GridView1.Rows
(DirectCast(r.FindControl("CheckBox1"), CheckBox)).Checked = True
        Next

    End Sub
Im getting curly on '(DirectCast)
why?
zachvaldezAsked:
Who is Participating?
 
viralypatelCommented:
use this:

For Each r As GridViewRow In GridView1.Rows
            Dim chkSel As CheckBox = DirectCast(r.FindControl("chkSelect"), CheckBox)
            chkSel.Checked = True
Next

Open in new window

0
 
CodeCruiserCommented:
To be on the safe side, first make sure that a control has been found because you will get a NullReferenceException otherwise




Protected Sub CheckBox2_CheckedChanged1(sender As Object, e As EventArgs)
        Dim ctrl as Object
        For Each r As GridViewRow In GridView1.Rows
           ctrl = r.FindControl("CheckBox1")
           If IsNothing(ctrl) = False Then
              CType(ctrl, Checkbox).Checked = True
           End If
        Next

End Sub

Open in new window

0
 
sachinpatil10dCommented:
change this
(DirectCast(r.FindControl("CheckBox1"), CheckBox)).Checked = True


to

DirectCast(r.FindControl("CheckBox1"), CheckBox).Checked = True
0
 
zachvaldezAuthor Commented:
The answers addressed the problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.