AddHandler not catching event for CheckBox in GridView

Posted on 2006-05-12
Last Modified: 2012-05-05
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"  >
                          <asp:CheckBox ID="CheckBox1" runat="server"  EnableViewState="true" AutoPostBack="true"/>

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: 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.
Question by:jschnei555
    LVL 5

    Accepted Solution

    Hi There,

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


    LVL 5

    Expert Comment


    AddHandler cb.Click, AddressOf Me.cb_CheckedChanged

    Author Comment

    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.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    iTextSharp resize image 2 27
    How to count json data 2 41
    Need Regex Money No $ 5 43 How to execute Page_Load One time 2 30
    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now