Question

The check box list has an event called "ItemChecked" or something, which triggers when an item is about to change its checked status.

So, it is before the check occurs.

I couldn't find an event that occurs after the item has changed.. I want to execute some code only when an item is checked or unchecked.

Was it helpful?

Solution

The CheckedChanged event occurs after the checkbox is checked or unchecked.

Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles CheckBox1.CheckedChanged
MsgBox(CheckBox1.Checked)
End Sub

OTHER TIPS

You can use that event and just reverse the checked status that the checkbox has at the time.

Once the event fires, the check (or uncheck) WILL happen no matter what, so you can just take the checkbox state and negate it to arrive at what it will be once the operation completes.

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       If CheckBoxList.Text = "" Then
            Label.Text &= "Error message here"
            Exit Sub
        Else
            For Each item As ListItem In CheckBoxList.Items
                If item.Selected Then
                    Label.Text &= "In the CBL you selected " & item.Value & "<br/>"
                End If
            Next
        End If
    End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top