ch3_25 listbox 1 >> listbox 2 (未分類)
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'註解 為 課文ch3_25
'For Each item As ListItem In CheckBoxList1.Items
' If item.Selected Then
' item.Selected = False
' ListBox1.Items.Add(item)
' End If
'Next
'For Each item As ListItem In ListBox1.Items
' If CheckBoxList1.Items.Contains(item) Then
' CheckBoxList1.Items.Remove(item)
' End If
'Next
Dim selectitems = From item In CheckBoxList1.Items.Cast(Of ListItem)() _
Where item.Selected Select item
For Each item In selectitems.ToArray()
item.Selected = False
ListBox1.Items.Add(item)
CheckBoxList1.Items.Remove(item)
Next
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim ary() As String = {"一", "二", "三", "四", "五", "六"}
CheckBoxList1.DataSource = ary
CheckBoxList1.DataBind()
End If
End Sub
End Class
如有錯誤 歡迎指正