Multi Selection in ListBox and Adding One ListBox to another Listbox in Asp.net c#
Aspx Page
<asp:ListBox ID="listboxEducation" runat="server" SelectionMode="Multiple" Height="150"></asp:ListBox>
<asp:ImageButton ID="imgAdd" ImageUrl="~/Hospital/icons/rightArrow.png" Height="25"
Width="25" runat="server" OnClick="imgAdd_Click" />
<asp:ImageButton ID="imgRemove" ImageUrl="~/Hospital/icons/leftArrow.png" Height="25"
Width="25" runat="server" onclick="imgRemove_Click"/>
<asp:ListBox ID="listboxEducationSelected" runat="server" SelectionMode="Multiple"
Height="150"></asp:ListBox>
.cs page c#.
{
int _count = listboxEducation.Items.Count;
if (_count != 0)
{
for (int i = 0; i < _count; i++)
{
if (listboxEducation.Items[i].Selected)
{
ListItem item = new ListItem();
item.Text = listboxEducation.Items[i].Text;
item.Value = listboxEducation.Items[i].Value;
listboxEducationSelected.Items.Add(item);
listboxEducation.Items[i].Enabled = false;
}
}
}
}
protected void imgAddExpertise_Click(object sender, ImageClickEventArgs e)
{
int _count = ListBoxExpertise.Items.Count;
if (_count != 0)
{
for (int i = 0; i < _count; i++)
{
if (ListBoxExpertise.Items[i].Selected)
{
ListItem item = new ListItem();
item.Text = ListBoxExpertise.Items[i].Text;
item.Value = ListBoxExpertise.Items[i].Value;
ListBoxExpertiseSelected.Items.Add(item);
ListBoxExpertise.Items[i].Enabled = false;
}
}
}
}
Comments
Post a Comment