lundi 17 février 2020

CheckboxList not returning correct checkbox values- html, asp.net, vb

I have 5 checkboxes in a checkboxlist and the last one is checked, however its not returning correct value.

Sample Checkboxes:

0

2

5

6

9- Checked

Html Code

<asp:CheckBoxList CssClass="form-control checkbox" ID="chkTest" runat="server" OnSelectedIndexChanged="chkTest_SelectedIndexChanged" AutoPostBack="true">

VB Code:

Protected Sub chkTest_SelectedIndexChanged(sender As Object, e As EventArgs)
    For i = 0 To chkTest.Items.Count - 1 Step 1
        If chkTest.Items(i).Selected Then
            list.Add(chkTest.Items(i).Value) 'Here when when the i=4, the checkbox value is still set to 6 or a random number
        End If
    ViewState("list") = list
End Sub



Aucun commentaire:

Enregistrer un commentaire