473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I move items between a databound box and another?

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

Expand|Select|Wrap|Line Numbers
  1. <script runat="server">
  2.     Protected Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
  3.         If ListBox2.Items.Count < 8 Then
  4.             For Each item As ListItem In ListBox1.Items
  5.                 If item.Selected And Not ListBox2.Items.Contains(item) Then
  6.                     Dim newItem As New ListItem(item.Text, item.Value)
  7.                     ListBox2.Items.Add(newItem)
  8.                 End If
  9.             Next
  10.         End If
  11.     End Sub
  12.     Protected Sub RemoveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveButton.Click
  13.         Dim itemsToRemove As New List(Of ListItem)
  14.         For Each item As ListItem In ListBox2.Items
  15.             If item.Selected Then
  16.                 itemsToRemove.Add(item)
  17.             End If
  18.         Next
  19.         For Each item As ListItem In itemsToRemove
  20.             ListBox2.Items.Remove(item)
  21.         Next
  22.     End Sub
  23.     Protected Sub RemoveAllButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RemoveAllButton.Click
  24.         ListBox2.Items.Clear()
  25.     End Sub
  26.  
  27.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  28.  
  29.     End Sub
  30.  
  31.     </script>
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml" >
  34. <head runat="server">
  35.     <title></title>
  36. </head>
  37. <body>
  38.     <form id="form1" runat="server">
  39.         <asp:AccessDataSource ID="ADS1" runat="server" 
  40.             DataFile="PGA.mdb"             
  41.             SelectCommand="SELECT [Player] FROM [Players] ORDER BY [order_lastname]">
  42.         </asp:AccessDataSource>
  43.  
  44.  
  45.         <asp:ListBox ID="ListBox1" runat="server" 
  46.             Rows="15" 
  47.             Width="200px" 
  48.             SelectionMode="Multiple" 
  49.             Enabled="True" 
  50.             DataSourceID="ADS1" 
  51.             DataTextField="Player" 
  52.             DataValueField="Player" >
  53.         </asp:ListBox>
  54.  
  55.             <asp:Button ID="AddButton" runat="server" Text=" > " />
  56.             <asp:Button ID="RemoveButton" runat="server" Text=" < " />
  57.             <asp:Button ID="RemoveAllButton" runat="server" Text=" << " />
  58.  
  59.         <asp:ListBox ID="ListBox2" runat="server" 
  60.             Rows="15" 
  61.             Width="200px" 
  62.             SelectionMode="Multiple">
  63.         </asp:ListBox>
  64.  
  65.     </form>
  66. </body>
  67.  
  68. </html>
  69.  
Attached Images
File Type: jpg boxes.jpg (14.3 KB, 71 views)
Mar 27 '14 #1
0 944

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Job Lot | last post by:
I have worked out how to move items in ListBox when it is populated using Items collection, but it doesn't seems to work when the ListBox is bound to a DataSource. How can i move items when...
1
by: Ashish | last post by:
I am looking for javascript code, which can add items in another frame. Scene: I have 3 frames A, B and C. A and C has links/queries that displays result items in B Results are with...
0
by: Stephen | last post by:
I was wondering if it is possible to take the contents of a row in a datagrid and use an event to copy over the details of the selected row into another datagrid. I'd like to be able to do the...
2
by: vijay | last post by:
Hi, Can we do something like we select nodes from one tree and when we press a button like "Add" It will move that node with its parent node to the tree to the right? Is this possible in...
1
by: SubashiniKumaar | last post by:
how to copy dropdownlist selected items to another dropdownlist in Asp.net using C# codings
4
by: bogdan | last post by:
Hi, I have two listboxes on a page and need to move items between them - using buttons (e.g. "<<" ">>"). Can this be done on a client side in asp.net? I'd like to avoid hitting the server on...
5
by: trixb | last post by:
Hello all, Here is what I need to do and need help with: I have a table that is feeding a chart in a report in Access. If this table has more than 50 records, the graph gets messy, and this is...
2
by: vinod allapu | last post by:
hi all, i am trying to generate a report, iam using sql server 2000 and Asp.net 2.0. First to select the columns iam using the list box... as we can order by the query result from the...
5
by: amandab116 | last post by:
I'm having a hard time figuring out how to move items between a left and right listbox server-side. I have a populated listbox from the database on the left and I'm trying to add items to the box...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.