<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication16.WebForm1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm1</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:ListBox Runat="server" ID="ListBox1" SelectionMode="Multiple"></asp:ListBox> <asp:Button Runat="server" ID="btnMoveRight" Text=" Move >> "></asp:Button> <asp:Button Runat="server" ID="btnMoveLeft" Text=" Move << "></asp:Button> <asp:ListBox Runat="server" ID="ListBox2" SelectionMode="Multiple"></asp:ListBox> </form> </body> </HTML>
private void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ListBox1.Items.Add("Java"); ListBox1.Items.Add("DOT NET"); ListBox1.Items.Add("PASCAL"); } } private void btnMoveRight_Click(object sender, System.EventArgs e) { for(int i=ListBox1.Items.Count-1;i>=0;i--) { if (ListBox1.Items[i].Selected==true) { ListBox2.Items.Add(ListBox1.Items[i]); ListItem li = ListBox1.Items[i]; ListBox1.Items.Remove(li); } } } private void btnMoveLeft_Click(object sender, System.EventArgs e) { for(int i=ListBox2.Items.Count-1;i>=0;i--) { if (ListBox2.Items[i].Selected==true) { ListBox1.Items.Add(ListBox2.Items[i]); ListItem li = ListBox2.Items[i]; ListBox2.Items.Remove(li); } } }