2010-07-19 71 views
0

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

<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 

回答

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

+0

它说:CheckBoxItem没有定义 – 2010-07-19 18:56:52

+0

不起作用,它没有检测到我检查了chec ked盒子。实际上我已经检查了一个复选框。我也有autopostback = true .... – 2010-07-19 19:07:59

+0

如果我点击复选框,它在哪里更新,我检查了这个复选框?我已尝试链接的示例表单,但它没有检测到我已检查。 – 2010-07-19 19:15:22