Learn how to a build a cloud-first strategyRegister Now


AddHandler not catching event for CheckBox in GridView

Posted on 2006-05-12
Medium Priority
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: 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.
Question by:jschnei555
  • 2

Accepted Solution

bullrout earned 2000 total points
ID: 16671728
Hi There,

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



Expert Comment

ID: 16671735

AddHandler cb.Click, AddressOf Me.cb_CheckedChanged

Author Comment

ID: 16671833
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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