请问大家是如何使用 ListBox 这个控件的
最好能详细些

解决方案 »

  1.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListBox.aspx.cs" Inherits="ListBox" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table style="width: 566px; text-align:center">
                <tr>
                    <td>
                        <asp:ListBox ID="ListBox1" runat="server" Width="250px">
                           <asp:ListItem>aa</asp:ListItem>
                           <asp:ListItem>bb</asp:ListItem>
                           <asp:ListItem>cc</asp:ListItem>
                           <asp:ListItem>dd</asp:ListItem>
                        </asp:ListBox></td>
                    <td><asp:Button ID="btn1" runat="server" Text=">>" OnClick="btn_Click"/><br /><asp:Button ID="btn2" runat="server" Text="<<" OnClick="btn2_Click"/></td>
                    <td>
                        <asp:ListBox ID="ListBox2" runat="server" Width="250px">
                           <asp:ListItem>aa</asp:ListItem>
                           <asp:ListItem>bb</asp:ListItem>
                        </asp:ListBox></td>
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class ListBox : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void btn_Click(object sender, EventArgs e)
        {
            if (ListBox1.SelectedIndex.ToString() == "-1")
                Response.Write("");
            else
            {
                if (ListBox2.Items.Contains(ListBox1.SelectedItem))
                    Response.Write("");
                else
                {
                    ListBox2.Items.Add(ListBox1.SelectedItem.Text);
                    ListBox1.Items.Remove(ListBox1.SelectedItem.Text);
                }
            }
        }
        protected void btn2_Click(object sender, EventArgs e)
        {
            if (ListBox2.SelectedIndex.ToString() == "-1")
                Response.Write("");
            else
            {
                if (ListBox1.Items.Contains(ListBox2.SelectedItem))
                    Response.Write("");
                else
                {
                    ListBox1.Items.Add(ListBox2.SelectedItem.Text);
                    ListBox2.Items.Remove(ListBox2.SelectedItem.Text);
                }
            }
        }
    }