What I really need is to actually move the item out of listbox1 when I put it in listbox2 and do the reverse. Now I am lost how to get the darn thing to let me actually move the items from listbox1 to listbox2 and back. I tried initially to use ListBox2.Items.Remove(item) which of course didn't work because the data in listbox1 is bound to a database and now I have been spinning my wheels for a couple days looking for the best way to make this work. Any assistance someone could provide would be a HUGE help.
Thanks
Expand|Select|Wrap|Line Numbers
- <script runat="server">
- Protected Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
- If ListBox2.Items.Count < 8 Then
- For Each item As ListItem In ListBox1.Items
- If item.Selected And Not ListBox2.Items.Contains(item) Then
- Dim newItem As New ListItem(item.Text, item.Value)
- ListBox2.Items.Add(newItem)
- End If
- Next
- End If
- End Sub
- Protected Sub RemoveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveButton.Click
- Dim itemsToRemove As New List(Of ListItem)
- For Each item As ListItem In ListBox2.Items
- If item.Selected Then
- itemsToRemove.Add(item)
- End If
- Next
- For Each item As ListItem In itemsToRemove
- ListBox2.Items.Remove(item)
- Next
- End Sub
- Protected Sub RemoveAllButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveAllButton.Click
- ListBox2.Items.Clear()
- End Sub
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
- End Sub
- </script>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <asp:AccessDataSource ID="ADS1" runat="server"
- DataFile="PGA.mdb"
- SelectCommand="SELECT [Player] FROM [Players] ORDER BY [order_lastname]">
- </asp:AccessDataSource>
- <asp:ListBox ID="ListBox1" runat="server"
- Rows="15"
- Width="200px"
- SelectionMode="Multiple"
- Enabled="True"
- DataSourceID="ADS1"
- DataTextField="Player"
- DataValueField="Player" >
- </asp:ListBox>
- <asp:Button ID="AddButton" runat="server" Text=" > " />
- <asp:Button ID="RemoveButton" runat="server" Text=" < " />
- <asp:Button ID="RemoveAllButton" runat="server" Text=" << " />
- <asp:ListBox ID="ListBox2" runat="server"
- Rows="15"
- Width="200px"
- SelectionMode="Multiple">
- </asp:ListBox>
- </form>
- </body>
- </html>