Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle two-way binding of a SqlDataSource on a ASP.NET ListBox
    text
    copied!<p>If I have two listboxes, with a button between them, how do I update the Items of ListBox2 if ListBox2's items are databound?</p> <pre><code>&lt;asp:ListBox runat="server" ID="ListBox1" DataSourceID="DataSource1" DataTextField="Name" DataValueField="ID" SelectionMode="Multiple" /&gt; &lt;asp:Button runat="server" ID="addButton" onClick="addButton_Click" /&gt; &lt;asp:ListBox runat="server" ID="ListBox2" DataSourceID="DataSource2" DataTextField="Name" DataValueField="ID" SelectionMode="Multiple" /&gt; </code></pre> <p>Also if I use the SelectionMode="Multiple", will I be able to Update the DataSource using an UpdateCommand that takes one item at a time?</p> <p>EDIT:</p> <p>Ok, to add some clarification:</p> <ul> <li>Both Listboxes are DataBound to unique data (SqlDataSource).</li> <li>I want to add items from ListBox1 to ListBox2 and vice versa, when a user clicks a button.</li> <li>I want to be able to add multiple items to the ListBox (presume that multiple selection is turned on)</li> <li>I want that to trigger an UpdateCommand on the DataSource.</li> </ul> <p>So far the only way I'm able to accomplish this is by manually taking each item from the first listBox and adding it as a parameter to the DataSource's UpdateCommand and manually call the SqlDataSource.Update() method. This works, but it means that I either need to pass a delimited string for multiple selections or open multiple connections. What I'm looking for is a way to update the DataSource on the ListBox and once it's fully updated, then call the Bind/Update and persist the data back to the DB.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload