1

I have a checkbox that is part of a repeater. I'm trying to get the checkbox's checkedchanged event to occur when I check the box and when I uncheck the box. The event currently only triggers when I check the box however... not when i uncheck also. I'll post some code below and hopefully someone can steer me in the right direction. Thanks!

Adding Handler to Repeater CheckBox Control

Dim MyCheckBox As New CheckBox

MyCheckBox = e.Item.FindControl("MyCheckBox")
AddHandler MyCheckBox.CheckedChanged, AddressOf MyCheckBox_CheckedChanged

My CheckedChanged Handler Event

    Private Sub MyCheckBox_CheckedChanged(sender As Object, e As System.EventArgs)
         Dim RepeaterItem As RepeaterItem

         For Each RepeaterItem In MyRepeater.Items
             If IsListItem(RepeaterItem) Then
                If CType(sender, CheckBox).Checked Then
                   CType(RepeaterItem.FindControl("SelectionCheckBox"), CheckBox).Checked = True
                Else
                   CType(RepeaterItem.FindControl("SelectionCheckBox"), CheckBox).Checked = False
                End If
             End If
         Next

    End Sub

ASPX File Check Box Declaration

<asp:CheckBox ID="MyCheckBox" AutoPostBack="True" Text="" runat="server" />
daveomcd
  • 6,367
  • 14
  • 83
  • 137
  • Why are you looping through your repeater to check/uncheck boxes on the checked changed event? They should maintain their state without you having to manually do this. – Cruril Sep 26 '12 at 20:41
  • Were is the CheckBox declared, in your .vb file or in your .aspx file? Assuming it is being declared in your .aspx file you should just hook the event there instead of doing it in code behind. – Peter Sep 26 '12 at 22:00
  • @Chris, I have a checkbox in the header template of my repeater and then a checkbox for each row in my repeater. I'm wanting to use the checkbox at the top to "select all" or "unselect all" – daveomcd Sep 26 '12 at 22:35

1 Answers1

2

Do you have AutoPostBack = true set up in your ASPX file.

arunlalam
  • 1,838
  • 2
  • 15
  • 23
  • @Wade73, Sorry this wasn't the correct answer I was saying I already had that in my code, but forgot to include it above in the question. Sorry for the confusion. It still works as I've described above. – daveomcd Sep 26 '12 at 23:14
  • 1
    @Daveomcd Sorry for the comment then, thanks for the clarification. – Wade73 Sep 27 '12 at 00:19