SANJISH 0 Newbie Poster

I have a checkbox inside a datalist control with Autopostback="True". When a user clicks the checkbox the associated event Handler is not firing.

My code is

In HTML :

<asp:DataList ID="myDataList" runat="server"  RepeatColumns="1"   RepeatDirection="Vertical" >
               <ItemTemplate>
                   <asp:CheckBox ID="chkid" runat="server" autopostback="True" />
                   <%#"Id " + Container.DataItem("CustomerID")%><br />
                   <%#"Name " + Container.DataItem("ContactName")%>
                   <br />
                   <br />

               </ItemTemplate>
         </asp:DataList>&nbsp;

In Code behind :

Protected Sub myDataList_ItemCreated(ByVal sender As Object, ByVal e As  system.Web.UI.WebControls.DataListItemEventArgs) Handles myDataList.ItemCreated

        Dim alSelectedValues As New ArrayList

        For Each item As DataListItem In myDataList.Items
            'check the item isn't a header or footer
            If e.Item.ItemIndex > -1 Then
                Dim cb As CheckBox = e.Item.FindControl("chkid")
                AddHandler cb.CheckedChanged, AddressOf Me.checkboxclicked

                Dim value As String = cb.Text
                Dim checked As Boolean = cb.Checked
                 If checked Then
                    alSelectedValues.Add(value)
                End If
            End If

        Next

The checkboxclicked event Handler is not firing

Please help

Regards

Sanjish

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.