如何确定检查的内容?

时间:2010-07-19 18:48:21

标签: asp.net vb.net

我有一个dropdwonlsit(加载在page_load事件上),一个未绑定的CheckBoxList基于DropDownlist的选择,checkboxList是显示CheckBox(可能是一个或两个或三个或任何数字).....我只是想要要知道在浏览器上加载页面并且用户点击复选框后,我需要一种方法来了解用户选择的复选框...这样做的最佳方式是什么?到目前为止,我已经想出了这个......

 <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

1 个答案:

答案 0 :(得分:0)

For Each checkBoxItem as CheckBoxItem in chkItems
 if checkBoxItem.Checked=true then
    list.add(chckboxItem.Value)
 end if
Next

请改为尝试:

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

以下是vb.net或C#中的示例链接:

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

相关问题