?
Solved

syntax error why

Posted on 2011-10-02
4
Medium Priority
?
196 Views
Last Modified: 2012-05-12
 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?
0
Comment
Question by:zachvaldez
4 Comments
 
LVL 12

Accepted Solution

by:
viralypatel earned 400 total points
ID: 36901577
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
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 200 total points
ID: 36902403
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
 
LVL 9

Assisted Solution

by:sachinpatil10d
sachinpatil10d earned 400 total points
ID: 36903235
change this
(DirectCast(r.FindControl("CheckBox1"), CheckBox)).Checked = True


to

DirectCast(r.FindControl("CheckBox1"), CheckBox).Checked = True
0
 

Author Closing Comment

by:zachvaldez
ID: 36909453
The answers addressed the problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question