Link to home
Start Free TrialLog in
Avatar of jschnei555
jschnei555

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of bullrout
bullrout

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bullrout
bullrout

also,

AddHandler cb.Click, AddressOf Me.cb_CheckedChanged
Avatar of jschnei555

ASKER

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.