20分,关于ListBox的问题,急!!!
我用了两个ListBox,左边的ListBox1通过双击将数据显示在ListBox2中。我要将ListBox2中显示的数据添加到数据库,ListBox2的数据都要添加。请问怎么将做,用的C#,帮帮忙!
[解决办法]
代码:
<%@ Page language= "c# " Codebehind= "WebForm1.aspx.cs " AutoEventWireup= "false " Inherits= "WebApplication1.WebForm1 " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " >
<HTML>
<HEAD>
<title> WebForm1 </title>
<meta content= "Microsoft Visual Studio .NET 7.1 " name= "GENERATOR ">
<meta content= "C# " name= "CODE_LANGUAGE ">
<meta content= "JavaScript " name= "vs_defaultClientScript ">
<meta content= "http://schemas.microsoft.com/intellisense/ie5 " name= "vs_targetSchema ">
<script language= "javascript ">
function RemoveAllEvent()
{
RemoveAll(window.document.getElementById( 'select1 '),window.document.getElementById( 'select2 '));
}
function AddAllEvent()
{
RemoveAll(window.document.getElementById( 'select2 '),window.document.getElementById( 'select1 '));
}
function RemoveOneEvent()
{
RemoveOne(window.document.getElementById( 'select1 '),window.document.getElementById( 'select2 '));
}
function AddOneEvent()
{
RemoveOne(window.document.getElementById( 'select2 '),window.document.getElementById( 'select1 '));
}
function RemoveAll(selectSource,selectGoal)
{
var length = selectSource.length;
for(i = 0;i < length;i++)
{
var text = selectSource.options(i).text;
var value = selectSource.options(i).value;
var oOption = document.createElement( "OPTION ");
selectGoal.options.add(oOption);
oOption.innerText = text;
oOption.value = value;
}
for(i = 0;i < length;i++)
{
selectSource.options.remove(0);
}
}
function RemoveOne(selectSource,selectGoal)
{
var ar = new Array();//用于存储选择的项的索引
var length = selectSource.length;
for(i = 0;i < length;i++)
{
if (selectSource.options(i).selected)
{
var text = selectSource.options(i).text;
var value = selectSource.options(i).value;
var oOption = document.createElement( "OPTION ");
selectGoal.options.add(oOption);
oOption.innerText = text;
oOption.value = value;
ar[ar.length + 1] = selectSource.options(i);
}
}
for(i = 0;i < length;i++)
{
for(j = 0;j < ar.length;j++)
{
if (selectSource.options(i) == ar[j])
{
selectSource.options.remove(i);
}
}
}
}
</script>
</HEAD>
<body ms_positioning= "GridLayout ">
<form id= "form1 " runat= "server ">
<FONT face= "宋体 "> </FONT>
<SELECT style= "WIDTH: 216px; HEIGHT: 264px " size= "16 " id= "select1 " multiple runat= "server " ondblclick = "RemoveOneEvent() ">
<OPTION value= "0 "> 你好0 </OPTION>
<OPTION value= "1 "> 你好1 </OPTION>
<OPTION value= "2 "> 你好2 </OPTION>
<OPTION value= "3 "> 你好3 </OPTION>
<OPTION value= "4 "> 你好4 </OPTION>
</SELECT> <INPUT id= "btnAddAll " style= "Z-INDEX: 103; LEFT: 264px; POSITION: absolute; TOP: 192px "
type= "button " value= " < < " onclick= "AddAllEvent() "> <INPUT id= "btnAddOne " style= "Z-INDEX: 105; LEFT: 264px; POSITION: absolute; TOP: 144px "
type= "button " value= " < " onclick= "AddOneEvent() "> <INPUT id= "btnRemoveOne " style= "Z-INDEX: 104; LEFT: 264px; POSITION: absolute; TOP: 96px "
type= "button " value= " > " onclick= "RemoveOneEvent() "> <INPUT style= "Z-INDEX: 102; LEFT: 264px; POSITION: absolute; TOP: 56px " type= "button " value= " > > "
id= "btnRemoveAll " onclick= "RemoveAllEvent() ">
<SELECT style= "Z-INDEX: 101; LEFT: 336px; WIDTH: 224px; POSITION: absolute; TOP: 16px; HEIGHT: 262px "
size= "16 " id= "select2 " multiple runat= "server " ondblclick = "AddOneEvent() ">
</SELECT>
</form>
</body>
</HTML>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的E-Mail:bdbox@163.com 请多指教!