Below is the page I have so far that works. I does allow me to select an item from the first listbox and put it in the 2nd listbox. I also figured out how to remove the items from the 2nd listbox. So I got this far and now I hit a wall.
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
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
Code:
<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>