<div>
<asp:ListBox ID="ListBox1" runat="server" Height="319px"
SelectionMode="Multiple" Width="187px">
<asp:ListItem>001</asp:ListItem>
<asp:ListItem>002</asp:ListItem>
<asp:ListItem>003</asp:ListItem>
<asp:ListItem>004</asp:ListItem>
<asp:ListItem>005</asp:ListItem>
<asp:ListItem>006</asp:ListItem>
</asp:ListBox>
<asp:Button ID="Button1" runat="server" οnclick="Button1_Click" Text="添加" />
<asp:Button ID="Button2" runat="server" Text="免除" οnclick="Button2_Click" />
<asp:ListBox ID="ListBox2" runat="server" Height="323px"
SelectionMode="Multiple" Width="192px"></asp:ListBox>
</div>
后台
List<ListItem> list = new List<ListItem>();
protected void Button1_Click(object sender, EventArgs e)// 增加
{
for (int i = ListBox1.Items.Count-1; i >= 0; i--)
{
if(ListBox1.Items[i].Selected==true)
{
list.Add(ListBox1.Items[i]);
ListBox1.Items.Remove(ListBox1.Items[i]);
}
}
for (int i = list.Count-1; i >=0; i--)
{
ListBox2.Items.Add(list[i]);
}
}
protected void Button2_Click(object sender, EventArgs e)//移除;‘’
{
for (int i = ListBox2.Items.Count - 1; i >= 0; i--)
{
if (ListBox2.Items[i].Selected == true)
{
list.Add(ListBox2.Items[i]);
ListBox2.Items.Remove(ListBox2.Items[i]);
}
}
for (int i = list.Count - 1; i >= 0;i-- )
{
ListBox1.Items.Add(list[i]);
}
}