日期:2014-05-18  浏览次数:20501 次

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> &nbsp;
<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 v