This is our code:
<div>
<table style="width: 349px">
<tr>
<td class="style1">
<asp:ListBox ID="leftbox" runat="server" Height="114px" Width="212px"
SelectionMode="Multiple" AutoPostBack="True">
</asp:ListBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text=">>" onclick="Button1_Click" /><br />
<asp:Button ID="Button2" runat="server" Text="<<" onclick="Button2_Click" />
</td>
<td>
<asp:ListBox ID="rightbox" runat="server" Height="117px" Width="231px"
SelectionMode="Multiple" AutoPostBack="True"></asp:ListBox>
</td>
</tr>
</table>
</div>
The code behind is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<string> list= GetNameList();
leftbox.DataSource = list;
leftbox.DataBind();
}
}
private static List<string> GetNameList()
{
List<string> list = new List<string>();
list.Add("keerthana");
list.Add("sirisha");
list.Add("anusha");
list.Add("Anuradha");
list.Add("Bhavani");
list.Add("divya");
list.Sort();
return list;
}
Please tell me how to add two or more selected items one by one from leftbox to rightbox, without using server-side code (as below):
protected void Button1_Click(object sender, EventArgs e)
{
if (leftbox.SelectedIndex != -1)
{
rightbox.Items.Add(leftbox.SelectedItem.Text);
leftbox.Items.Remove(leftbox.SelectedItem.Text);
}
}
Thanks in advance…
Here is Linq way of get selected items form ListBox
then you can add all selected values to
rightboxand finally remove fromleftboxEDIT