//前台代码:
<%@ 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>
<script language="javascript" type="text/javascript">
function btn_right_onclick()
{
var select_ListBox_left = document.getElementById("ListBox_left");
var select_ListBox_right = document.getElementById("ListBox_right");
var count = 0;
for(i = 0; i < select_ListBox_left.length; i ++)
{ count = 0;
if(select_ListBox_left.options[i].selected)
{
var temp = document.createElement("option");
temp.value = select_ListBox_left[i].value;
temp.text = select_ListBox_left[i].value;
if(select_ListBox_right.length == 0)
{
select_ListBox_right.add(temp);
}
else
{
for(j = 0; j < select_ListBox_right.length; j ++)
{
if(select_ListBox_right.options[j].value == temp.value)
{
count++;
}
}
if(count == 0)
{
select_ListBox_right.add(temp);
}
}
}
}
}
function btn_QuanBu_right_onclick()
{
var select_ListBox_left = document.getElementById("ListBox_left");
var select_ListBox_right = document.getElementById("ListBox_right");
for(i = select_ListBox_right.length; i >= 0; i --)
{
select_ListBox_right.remove([i]);
}
if(select_ListBox_right.length == 0)
{
for(i = 0; i < select_ListBox_left.length; i ++)
{
var temp = document.createElement("option");
temp.value = select_ListBox_left[i].value;
temp.text = select_ListBox_left[i].value;
select_ListBox_right.add(temp);
}
}
}
function btn_left_onclick()
{
var select_ListBox_right = document.getElementById("ListBox_right");
var tmp = select_ListBox_right.length;
for(i = 0; i < select_ListBox_right.length; i ++)
{ //alert(select_ListBox_right.length);
if(select_ListBox_right.options[i].selected)
{ //alert(i);
select_ListBox_right.remove([i]);
i--;
}
}
}
function btn_QuanBu_left_onclick()
{
var select_ListBox_left = document.getElementById("ListBox_left");
var select_ListBox_right = document.getElementById("ListBox_right");
for(i = select_ListBox_right.length; i >= 0; i --)
{
select_ListBox_right.remove([i]);
}
}
function btn_top_onclick()
{
var select_ListBox_right = document.getElementById("ListBox_right");
var selectedIndex = select_ListBox_right.selectedIndex;
var count = 0;
if(select_ListBox_right.length != 0)
{
for(i = 0; i < select_ListBox_right.length; i ++)
{
if(selectedIndex != 0)
{
if(select_ListBox_right.options[i].selected)
{
count ++;
}
}
else
{
return;
}
}
if(count != 0)
{
if(selectedIndex <= select_ListBox_right.length-1)
{
var temp = document.createElement("option");
temp.text = select_ListBox_right.options[select_ListBox_right.selectedIndex].text;
temp.value = select_ListBox_right.options[select_ListBox_right.selectedIndex].value;
select_ListBox_right.options[select_ListBox_right.selectedIndex].text = select_ListBox_right.options[select_ListBox_right.selectedIndex - 1].text;
select_ListBox_right.options[select_ListBox_right.selectedIndex].value = select_ListBox_right.options[select_ListBox_right.selectedIndex - 1].value;
select_ListBox_right.options[select_ListBox_right.selectedIndex - 1].text = temp.text;
select_ListBox_right.options[select_ListBox_right.selectedIndex - 1].value = temp.value;
select_ListBox_right.selectedIndex = select_ListBox_right.selectedIndex - 1;
}
}
else
{
alert("没有选中一个!");
}
}
else
{
alert("没有数据");
}
}
function btn_bottom_onclick()
{
var select_ListBox_right = document.getElementById("ListBox_right");
var selectedIndex = select_ListBox_right.selectedIndex;
var count = 0;
if(select_ListBox_right.length != 0)
{
for(i = 0; i < select_ListBox_right.length; i ++)
{
if(selectedIndex != select_ListBox_right.length-1)
{
if(select_ListBox_right.options[i].selected)
{
count ++;
}
}
else
{
return;
}
}
if(count != 0)
{
if(selectedIndex <= select_ListBox_right.length-1)
{
var temp = document.createElement("option");
temp.text = select_ListBox_right.options[select_ListBox_right.selectedIndex].text;
temp.value = select_ListBox_right.options[select_ListBox_right.selectedIndex].value;
select_ListBox_right.options[select_ListBox_right.selectedIndex].text = select_ListBox_right.options[select_ListBox_right.selectedIndex + 1].text;
select_ListBox_right.options[select_ListBox_right.selectedIndex].value = select_ListBox_right.options[select_ListBox_right.selectedIndex + 1].value;
select_ListBox_right.options[select_ListBox_right.selectedIndex + 1].text = temp.text;
select_ListBox_right.options[select_ListBox_right.selectedIndex + 1].value = temp.value;
select_ListBox_right.selectedIndex = select_ListBox_right.selectedIndex + 1;
}
}
else
{
alert("没有选中一个!");
}
}
else
{
alert("没有数据");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="250px" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><asp:ListBox ID="ListBox_left" SelectionMode="Multiple" Height="200px" Width="110px" runat="server"></asp:ListBox></td>
<td>
<input id="btn_right" type="button" value=" > " onclick="return btn_right_onclick()" />
<input id="btn_QuanBu_right" type="button" value=" >> " onclick="return btn_QuanBu_right_onclick()" />
<input id="btn_left" type="button" value=" < " onclick="return btn_left_onclick()" />
<input id="btn_QuanBu_left" type="button" value=" << " onclick="return btn_QuanBu_left_onclick()" />
<input id="btn_top" type="button" value=" ↑ " onclick="return btn_top_onclick()" />
<input id="btn_bottom" type="button" value=" ↓ " onclick="return btn_bottom_onclick()" />
</td>
<td><asp:ListBox ID="ListBox_right" SelectionMode="Multiple" Height="200px" Width="110px" runat="server"></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)
{
if (!IsPostBack)
{
ListBox_DataBind();
}
}
private void ListBox_DataBind()
{
XBGQWZ.BusinessLayer.T_Modle bus_role = new XBGQWZ.BusinessLayer.T_Modle();
DataSet ds = bus_role.GetList("");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
this.ListBox_left.Items.Add(ds.Tables[0].Rows[i][1].ToString());
}
}
}


浙公网安备 33010602011771号