日期:2014-05-18 浏览次数:20504 次
<select id="select2" style="height: 108px;width:100px;" runat="server" multiple="true"> </select>
protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { string k = ""; for (int i = 0; i < this.select2.Items.Count; i++) { k += this.select2.Items[i].Text; Response.Write(k); } }
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script type="text/javascript"> function additemSelect() { var sel = document.getElementById('<%=select2.ClientID %>'); sel.add(new Option("test1", 0)); sel.add(new Option("test2", 1)); } </script> </head> <body> <form id="form1" runat="server"> <div> <select id="select2" style="height: 108px; width: 100px;" runat="server"> </select> <input type="button" id="btn1" value="ADD" onclick="additemSelect()" /> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </div> </form> </body> </html>
------解决方案--------------------
window.onload = function(){ var o = document.getElementById("select1"); for(var i=0;i<50;i++){ o.options.add( new Option("UserName_"+i,i)) } }
------解决方案--------------------
这不奇怪,本来就是这样的,如果你要在服务器端获取的话,可以这样:
在提交时用javascript选中所有下拉框中的项,这样提交后通过Request.Form["下拉框name"]就能取到所有选中项的值,这个值是一个以,分隔的字符串
===================================================
ASP.NET WebForm和ASP.NET MVC分页最终解决之道