AddHandler not catching event for CheckBox in GridView

I have this gridview with a checkbox whose checked event I'm trying to capture :

 <asp:GridView ID="RMAGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="UID"  >
        <Columns>
...
               <asp:TemplateField>
                     <ItemTemplate>
                          <asp:CheckBox ID="CheckBox1" runat="server"  EnableViewState="true" AutoPostBack="true"/>
                     </ItemTemplate>
               </asp:TemplateField>
        </Columns>
 </asp:GridView>
       

Here's where I add the handler:

       Protected Sub RMAGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles      RMAGridView.RowDataBound
...
   
             If e.Row.RowType = DataControlRowType.DataRow Then
   ...      
                 Dim cb As CheckBox = CType(e.Row.Cells(12).Controls(1), CheckBox)
                 AddHandler cb.CheckedChanged, AddressOf cb_CheckedChanged

             End If

     End Sub

     Public Sub cb_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)

     End Sub



The problem is that when I check one of those checkboxes, a postback does take place but cb_CheckChanged is never called.  Am I missing something here?  I've seen several examples, including this one: http://www.vbcity.com/forums/faq.asp?fid=37&cat=Web+Development&#TID117940 and just don't see what I'm doing wrong.  I know this is the weekend, but I'm hoping for a pretty quick response.
jschnei555Asked:
Who is Participating?
 
bullroutCommented:
Hi There,

The example you have shown uses the ItemCreated event, try using that event first then try:

RMAGridView.Controls.Add(cb)

Sean
0
 
bullroutCommented:
also,

AddHandler cb.Click, AddressOf Me.cb_CheckedChanged
0
 
jschnei555Author Commented:
Protected Sub RMAGridView_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles RMAGridView.RowCreated
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim cb As CheckBox = CType(e.Row.Cells(12).Controls(1), CheckBox)
            AddHandler cb.CheckedChanged, AddressOf cb_CheckedChanged
        End If
    End Sub

That did it.  Thanks for the quick response.
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.