2010-07-19 88 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