tags:

views:

31

answers:

1

i havea dropdwonlsit (loads on the page_load event) and a unbound CheckBoxList is based on the selection from DropDownlist, the checkboxList is display CheckBox (might be one or two or three or any numbers)..... i just want to know after the page is loaded on the browser and user click on the checkbox's, i need a way to know what checkboxs users have selected... what is the best way of doing that? so far i have come up with this...

 <asp:CheckBoxList AutoPostBack="true" ID="chkbox" runat="server" RepeatColumns="2"      RepeatDirection="Horizontal" RepeatLayout="Table">
                        </asp:CheckBoxList>

  Private Sub chk_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chk.SelectedIndexChanged


        Dim roleCollections As New RoleCollections()
        Dim roleNames As New RoleNames()

        Dim list As New List(Of String)()

        For Each li As ListItem In chk.Items
            'If li.Selected Then 
                'list.Add(li.Value)
            'End If
        Next
A: 
For Each checkBoxItem as CheckBoxItem in chkItems
 if checkBoxItem.Checked=true then
    list.add(chckboxItem.Value)
 end if
Next

Try this instead:

For i=0 to chkItems.Items.Coult-1
 if chkItems.Items(i).Selected then
   list.add(chkItems.Items(i).Text)
 end if
next

Here is a link with an example in vb.net or C#:

http://authors.aspalliance.com/aspxtreme/aspnet/syntax/checkboxlistwebcontrol.aspx

JonH
it says: CheckBoxItem is not defined
Abu Hamzah
@JonH: does not work, its not detecting that i have check the checked box. in fact i have check one checkbox. also i have autopostback=true....
Abu Hamzah
if i click the checkbox where does it updating that i have checked this checkbox? i have try the sample form the link but it does not detect that i have checked.
Abu Hamzah
@teki it is working fine for me.Create a new solution in visual studio and add a checkboxlist control and set Autopostback to true. In your page load even make sure you are checking if you are posting back or not. If Not Page.IsPostBack 'process end if
JonH
@John, it does not work, it does not recoginize the CheckBoxItem ... do you see that i am using <asp:CheckBoxList
Abu Hamzah