Link to home
Start Free TrialLog in
Avatar of JOHNFROG
JOHNFROG

asked on

How to best count the checked checkboxes in a datagrid after each selection/deselection

I am trying to keep a running total of the number of checkboxes selected in a datagrid. My problem is not in the coding but how to invoke the code after each selection/deselection?

The default event for the checkbox is
Protected Sub CheckBox_Select_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

however this event is not triggered when a checkbox is changed.

any clues to why this would not be trigerred? could it be something to do with masterpages? or being inside an accordion control
' This code works if I request it from a button but the 
 
    Protected Sub CheckBox_Select_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cb As CheckBox
        Dim row As GridViewRow
        Dim contactCounter As Integer = 0
 
        For Each row In GridView1.Rows
            cb = CType(row.FindControl("CheckBox_Select"), CheckBox)
            If cb.Checked Then
                contactCounter = contactCounter + 1
            End If
        Next
        Label_contactsSelected.Text = contactCounter & " contacts selected"
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JasonChandler
JasonChandler

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 JOHNFROG
JOHNFROG

ASKER

good one. thanks for that. i should have spotted that. works great now.