<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function addSrcToDestList() {
destList = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList.length;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {var found = false;
for(var count = 0; count < len; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
      }
   }
}
if (found != true) {
destList.options[len] = new Option(srcList.options[i].text);
len++;
         }
      }
   }
}function deleteFromDestList() {
var destList  = window.document.forms[0].destList;
var len = destList.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
destList.options[i] = null;
      }
   }
}
// -->
</SCRIPT>
</head>
<body>
<center>
<form method="POST">
<table bgcolor="#FFFFCC"><tr>
<td bgcolor="#FFFFCC" width="85">
<select size="6" name="srcList" multiple>
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6
</select>
</td>
<td bgcolor="#FFFFCC" width="74" align="center">
<input type="button" value=" 增加到右边 " onClick="javascript:addSrcToDestList()">
<br><br>
<input type="button" value=" 从右边删除 " onclick="javascript:deleteFromDestList();">
</td>
<td bgcolor="#FFFFCC" width="69">
<select size="6" name="destList" multiple>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>

解决方案 »

  1.   

    换句话说在前台(浏览器)中,用javascript添加的项,在后台(服务器)代码用ListBox.Items根本就取不到。
    我在做联动下拉框的时候也遇到过同样的问题,估计是.net的bug。
    后来我设置了一个<input type=hidden>,添加一个onchange时间用来把值放在里面,这时候后台就可以取到值了,你也可以参考一下,试试其它控件来存值,然后隐藏。
      

  2.   

    我添加了一个<input type="hidden" id="most" runat="server">然后在我右边的listbox添加了onchange事件
    <asp:listbox id="most_exit_products2" runat="server" Width="165px" Rows="10" onchange="javascript:addit();">函数addit()
    function addit()
    {
       most.value=most_exit_products2.options[0].text;
    }然后在后台我想取到most.value值如下string cc=most.Value;
    Response.Write(cc);
    Response.End();但是cc却是空!!还是取不到啊?
    怎么回事?
      

  3.   

    我用的是一个控件,好象取道过,呵呵名字叫做:DualSelectListBoxSetup.msi
    大家可以到网上找找看,我是在www.asp.net的控件谷里面找到的
      

  4.   

    看了一下楼主的代码,addit()事件添加得是不是有问题,
    private void Page_Load( object sender , System.EventArgs e )
    {
         ................
         most_exit_products2.Attirbutes.Add("onclick","addit();");
         ................
    }
      

  5.   


    http://www.metabuilders.com/Tools/DualList.aspx这个控件完全实现你的功能。
      

  6.   

    to   sfar(daydayup)
    用你的方法仍然是不行的。
      

  7.   

    to litp(天道酬勤) 看你的例子很好用,不过用2002打不开,有解决办法么?
      

  8.   

    打开页面的智能导航就OK了(smartNavigeting=true)
      

  9.   

    我爱你啊  liuchengdan(史前大毛兽) ,你太可爱了!!!!
    SmartNavigation=true;搞定!
      

  10.   

    2003用smartnavigation好像不可以,最后还是dynamiclistbox control