><%@ Page Language="vb" AutoEventWireup="false" >Codebehind="listboxmultiple.aspx.vb" Inherits="p450work2.listboxmultiple" ><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ><html> > <head> > <title>listboxmultiple</title> > <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR"> > <meta content="Visual Basic 7.0" name="CODE_LANGUAGE"> > <meta content="JavaScript" name="vs_defaultClientScript"> > <meta content="http://schemas.microsoft.com/intellisense/ie5" >name="vs_targetSchema"> > </head> > <body> > <form id="Form1" method="post" runat="server"> > <p><asp:listbox id="ListBox1" runat="server" selectionmode="Multiple"> > <asp:listitem value="Red">Red</asp:listitem> > <asp:listitem value="Green">Green</asp:listitem> > <asp:listitem value="Blue">Blue</asp:listitem> > <asp:listitem value="White">White</asp:listitem> > <asp:listitem value="Black">Black</asp:listitem> > </asp:listbox><asp:listbox id="ListBox2" >runat="server"></asp:listbox></p> > <p> > <asp:button id="Button1" runat="server" text="Move >"></asp:button></p> > <p> </p> > </form> > </body> ></html> >>
>Public Class listboxmultiple > Inherits System.Web.UI.Page > Protected WithEvents Button1 As System.Web.UI.WebControls.Button > Protected WithEvents ListBox2 As System.Web.UI.WebControls.ListBox > Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox > >#Region " Web Form Designer Generated Code " > > 'This call is required by the Web Form Designer. > <System.Diagnostics.DebuggerStepThrough()> Private Sub >InitializeComponent() > > End Sub > > Private Sub Page_Init(ByVal sender As System.Object, ByVal e As >System.EventArgs) Handles MyBase.Init > 'CODEGEN: This method call is required by the Web Form Designer > 'Do not modify it using the code editor. > InitializeComponent() > End Sub > >#End Region > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As >System.EventArgs) Handles MyBase.Load > 'Put user code to initialize the page here > End Sub > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >System.EventArgs) Handles Button1.Click > Dim li As ListItem > For Each li In ListBox1.Items > If li.Selected = True Then > ListBox2.Items.Add(New ListItem(li.Text, li.Value)) > End If > Next > Dim x As Integer > For x = (ListBox1.Items.Count - 1) To 0 Step -1 > If ListBox1.Items(x).Selected = True Then > ListBox1.Items.RemoveAt(ListBox1.Items.IndexOf(ListBox1.Items(x))) > End If > Next > End Sub > >End Class >>