Populating ListBox with the selected Items from other LisBox.
The ListBox is populated with the selected items of the second listbox control
<asp:ListBox ID="ListBox1" SelectionMode="Multiple" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:ListBox> <asp:ListBox ID="ListBox2" SelectionMode="Multiple" runat="server"> </asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> |
protected void Button1_Click(object sender, EventArgs e)
{
foreach (ListItem item in ListBox1.Items)
{
if (item.Selected == true)
{
ListBox2.Items.Add(item);
}
}
} |