我有一個checkboxlist whith幾個選項。所選的選項將從第二個複選框列表中刪除。這在以下代碼中正常工作。問題是,當用戶更改複選框列表1中的選定選項時,第二個複選框列表仍保留原始選項。我該如何改變這一點?注意:下拉列表有助於用戶繼續使用表單。如何返回已被刪除的listitem?
page.aspx
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="true"> <asp:ListItem Value="3">Italian</asp:ListItem>
<asp:ListItem Value="6">Chinese</asp:ListItem>
<asp:ListItem Value="7">Japanese</asp:ListItem>
<asp:ListItem Value="8">Russian</asp:ListItem>
<asp:ListItem Value="9">Arabic</asp:ListItem>
<asp:ListItem Value="10">Hebrew</asp:ListItem>
<asp:ListItem Value="11">Persian</asp:ListItem>
<asp:ListItem Value="12">Turkish</asp:ListItem>
</asp:CheckBoxList>
...
<asp:DropDownList ID="DropDownList1" Width="100px" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="">Select</asp:ListItem>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>
page.aspx.vb
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim li2 As ListItem
Dim values As String = ""
For i As Integer = 0 To CheckBoxList1.Items.Count - 1
If CheckBoxList1.Items(i).Selected Then
values += CheckBoxList1.Items(i).Value + ","
End If
Next
values = values.TrimEnd(","c)
Dim ints As String() = values.ToString.Split(",")
Dim y As Integer
If DropDownList1.SelectedValue = "Yes" Then
For y = 0 To UBound(ints)
li2 = CheckBoxList2.Items.FindByValue(ints(y))
If Not IsNothing(li2) Then
CheckBoxList2.Items.Remove(li2)
End If
Next
end if
End Sub
謝謝,我現在正在檢索,添加和刪除代碼背後的listitems,並正常工作。 – netNewbi3 2011-06-16 11:55:09