列表选择listbox1-->listbox2

本文介绍了一个使用ASP.NET实现的工作人员选择界面,该界面通过下拉列表选择班组,并从对应的人员列表中选择或转移人员。文章展示了完整的ASP.NET页面代码,包括HTML结构、样式设置及C#后台逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OverTime.aspx.cs" Inherits="OverTime" %>

<!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 id="Head1" runat="server">
<title>Untitled Page</title>
<style type="text/css">
#div1
{
width: 606px;
height: 400px;
border: 1px solid #ffffff;
}
#div2
{
position: absolute;
left: 5px;
width: 200px;
height: 400px;
border: 1px solid #ffffff;
}
#div3
{
top: 150px;
text-align: center;
position: absolute;
left: 205px;
width:50px;
height: 100px;
border: 1px solid #ffffff;
}
#div4
{
position: absolute;
left: 255px;
width: 200px;
height: 400px;
border: 1px solid #ffffff;
}

</style>
</head>
<body>
<form id="form1" runat="server">
<br />
<br />
<br />
班组:<br />
<asp:DropDownList ID="DropDownList1" runat="server" Height="40px" Width="188px"
AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="bm_name"
DataValueField="bm_name">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=SRV-KS-DB;Initial Catalog=form_new1;Persist Security Info=True;User ID=ten;Password=19850610"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [bm_name] FROM [All_bm]"></asp:SqlDataSource>
<div id="div1">
<div id="div2">
<asp:ListBox ID="ListBox1" runat="server" Height="390px" Width="190px"
DataSourceID="SqlDataSource2" DataTextField="ry_name" DataValueField="ry_name"
></asp:ListBox>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="Data Source=SRV-KS-DB;Initial Catalog=form_new1;Persist Security Info=True;User ID=ten;Password=19850610"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [ry_name] FROM [All_user] WHERE ([bm_name] = @bm_name)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="bm_name"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
<div id="div3">
<table cellpadding="0" cellspacing="0" >
<tr>
<td>

</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text=">" Width="25px"
onclick="Button1_Click" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button2" runat="server" Text=">>" Width="25px"
onclick="Button2_Click" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button3" runat="server" Text="<" Width="25px"
onclick="Button3_Click" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button4" runat="server" Text="<<" Width="25px"
onclick="Button4_Click" />
</td>
</tr>
</table>
</div>
<div id="div4">
<asp:ListBox ID="ListBox2" runat="server" Height="390px" Width="190px"></asp:ListBox>
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></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 OverTime : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected == true)
{
ListBox2.Items.Add(new ListItem(ListBox1.Items[i].Text, ListBox1.Items[i].Value));
ListBox1.Items.Remove(ListBox1.Items[i].Value);
}
}
}
protected void Button3_Click(object sender, EventArgs e)
{
for (int i = 0; i < ListBox2.Items.Count; i++)
{
if (ListBox2.Items[i].Selected == true)
{
ListBox1.Items.Add(new ListItem(ListBox2.Items[i].Text, ListBox2.Items[i].Value));
ListBox2.Items.Remove(ListBox2.Items[i].Value);
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
ListBox1.DataBind();
ListBox2.DataSource = ListBox1.Items;
ListBox2.DataBind();
ListBox1.Items.Clear();
}
protected void Button4_Click(object sender, EventArgs e)
{
ListBox2.Items.Clear();
ListBox1.DataBind();
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值