Populate ListBox using selected Items of other ListBox Control.

Madhuk
Posted by Madhuk under ASP.NET category on | Points: 40 | Views : 3226
The following code is to populate the listbox items which are the selected items in other ListBox.

<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);
}
}
}

Comments or Responses

Login to post response