Link to home
Start Free TrialLog in
Avatar of Fishin4Walleye
Fishin4Walleye

asked on

Move specific row from one datatable to another

I have a simple .aspx webpage  with two listboxes.  I start on the initial page load by binding Listbox1 to a datatable and Listbox2 to another datatable :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Label1.Text = ADS1.ConnectionString
        If Not Page.IsPostBack Then
            ListLoad()
        End If
End Sub

Private Sub ListLoad()
        Dim dv As System.Data.DataView = CType(ADS1.Select(DataSourceSelectArguments.Empty), System.Data.DataView)
        dt = dv.ToTable
        cdt = dt.Clone
        
        ListBox1.DataSource = dt
        ListBox1.DataValueField = "ID"
        ListBox1.DataTextField = "FullName"
        ListBox1.DataBind()

        ListBox2.DataSource = cdt
        ListBox2.DataValueField = "ID"
        ListBox2.DataTextField = "FullName"
        ListBox2.DataBind()    
End Sub

Open in new window

So far everything is working fine and I have the two listboxes to play around with and can move stuff back and forth once the listboxes have been bound to a null.  My issue is trying to move the data in the datatables back and forth (which is why I set up two datatables and bound the listboxes in the first place).  Could someone please explain and possibly provide an example of how I could find the associated row in dt and move it to cdt if that corresponding row in listbox1 is selected?  Ideally I want to be able to handle multiple selected values in Listbox1 use  'For Each item As ListItem In ListBox1.Items...Next'  to handle this.  Thanks a ton!
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial