Asp.net 两个ListBox之间的选项传递(服务器端实现)

页面:


    
One Two Three





后台:

 Private Sub MoveItems(isAdd As Boolean)
        Dim i As Integer

        If (isAdd) Then
            i = ListBox1.Items.Count - 1

            Do While i >= 0
                If ListBox1.Items(i).Selected Then
                    ListBox2.Items.Add(ListBox1.Items(i))
                    ListBox2.ClearSelection()
                    ListBox1.Items.Remove(ListBox1.Items(i))
                    i = i - 1
                Else
                    i = i - 1
                End If
            Loop
        Else

            i = ListBox2.Items.Count - 1
            Do While i >= 0
                If ListBox2.Items(i).Selected Then
                    ListBox1.Items.Add(ListBox2.Items(i))
                    ListBox1.ClearSelection()
                    ListBox2.Items.Remove(ListBox2.Items(i))
                    i = i - 1
                End If
                i = i - 1
            Loop
        End If

    End Sub

    Private Sub MoveAllItems(isAddAll As Boolean)
        Dim i As Integer

        If (isAddAll) Then
            i = ListBox1.Items.Count - 1

            Do While i >= 0
                ListBox2.Items.Add(ListBox1.Items(i))
                ListBox2.ClearSelection()
                ListBox1.Items.Remove(ListBox1.Items(i))
                i = i - 1
            Loop

        Else
            i = ListBox2.Items.Count - 1

            Do While i >= 0
                ListBox1.Items.Add(ListBox2.Items(i))
                ListBox1.ClearSelection()
                ListBox2.Items.Remove(ListBox2.Items(i))
                i = i - 1
            Loop
        End If

    End Sub

    Protected Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click
        Call MoveItems(True)
    End Sub

    Protected Sub ButtonRemove_Click(sender As Object, e As EventArgs) Handles ButtonRemove.Click
        Call MoveItems(False)
    End Sub

    Protected Sub ButtonAddAll_Click(sender As Object, e As EventArgs) Handles ButtonAddAll.Click
        Call MoveAllItems(True)
    End Sub

    Protected Sub ButtonRemoveAll_Click(sender As Object, e As EventArgs) Handles ButtonRemoveAll.Click
        Call MoveAllItems(False)
    End Sub

参考链接:
https://social.msdn.microsoft.com/Forums/sqlserver/ja-JP/93c0b3b1-6f91-4487-aa62-c32db0e9e0a4?forum=aspnetja

你可能感兴趣的:(Asp.net 两个ListBox之间的选项传递(服务器端实现))