Default.aspx |
<form id="Form1" runat="server"> <asp:Table ID="Table1" runat="server"> <asp:TableRow> <asp:TableCell> <asp:ListBox SelectionMode="Multiple" ID="ListBox1" runat="server" Width="100" Height=100> <asp:ListItem Value="1">1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> <asp:ListItem Value="4">4</asp:ListItem> <asp:ListItem Value="5">5</asp:ListItem> </asp:ListBox> </asp:TableCell> <asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle"> <asp:Button ID="Button2" runat="server" Text=">>" onclick="Button2_Click" /> <br /><br /> <asp:Button ID="Button3" runat="server" Text="<<" onclick="Button3_Click" /> </asp:TableCell> <asp:TableCell> <asp:ListBox SelectionMode="Multiple" ID="ListBox2" runat="server" Width="100" Height=100></asp:ListBox> </asp:TableCell> </asp:TableRow> </asp:Table> </form> |
Default.aspx.vb |
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click For Each li As ListItem In ListBox1.Items If li.Selected Then li.Selected = False ListBox2.Items.Add(li) End If Next For Each li As ListItem In ListBox2.Items If ListBox1.Items.Contains(li) Then ListBox1.Items.Remove(li) End If Next End Sub Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click For Each li As ListItem In ListBox2.Items If li.Selected Then li.Selected = False ListBox1.Items.Add(li) End If Next For Each li As ListItem In ListBox1.Items If ListBox2.Items.Contains(li) Then ListBox2.Items.Remove(li) End If Next End Sub |