How do I reference a dynamically added CheckBox control?

I've added a CheckBox control during RowDataBound of the gridView control.  Like:

Dim chk As New CheckBox
cell = e.Row.Cells(0)
chk.ID = "IsSelected"
cell.Controls.Add(chk)

How do I reference the value of that CheckBox outside of the RowDataBound event?
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
Alfred A.Commented:
Or, in your case, something like this,

            Dim chk As CheckBox
           
            For Each item As GridViewRow In GridView1.Rows
                chk = CType(item.Cells(0).FindControl("chkSelect"), CheckBox)
                Dim ID as String = chk.ID
            Next
0
 
Alfred A.Commented:
You can do it something like this,

            Dim cb As CheckBox
           
            For Each item As GridViewRow In GridView1.Rows
                cb = CType(item.Cells(0).FindControl("chkSelect"), CheckBox)
                If cb.Checked = True Then
                    ''Do Something
                End If
            Next
0
 
HLRosenbergerAuthor Commented:
Thanks!!  That did the trick!
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.