获取使用ASP.net C#从HTML选择列表中的所有项目 [英] Get all items from html select list using ASP.net C#
本文介绍了获取使用ASP.net C#从HTML选择列表中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下选择列表:
<选择名称=上下文ID =上下文大小=5>
<选项>&CONTEXT1 LT; /选项>
<选项> Context2< /选项>
<选项> Context3< /选项>
<选项> Context4< /选项>
<选项> Context5< /选项>
< /选择>
我使用JavaScript来推动这一选择列表上下的项目(这是工作)。我想用C#生成的订单反馈到ASP.net。
如果我用code的下面一行我得到的只有选定的项目,我如何才能使整个列表?
字符串项=的Request.Form [上下文];
解决方案
您可以得到这样的所有项目。
VAR ddlArray =新的Array();
VAR DDL =的document.getElementById('语境');
对于(i = 0; I< ddl.options.length;我++){
ddlArray [I] = DDL可供选项[I] .value的;
}
现在通过这个JavaScript数组您code后面。
I have the following select list:
<select name="Context" id="Context" size="5">
<option>Context1</option>
<option>Context2</option>
<option>Context3</option>
<option>Context4</option>
<option>Context5</option>
</select>
I am using javascript to move the items of this select list up and down (this is working). I would like to feed the resulting order back to ASP.net using C#.
If I use the following line of code I get only the selected item, how do I get the whole list?
string items = Request.Form["Context"];
解决方案
You can get all items like this.
var ddlArray= new Array();
var ddl = document.getElementById('Context');
for (i = 0; i < ddl.options.length; i++) {
ddlArray[i] = ddl .options[i].value;
}
Now pass this JavaScript array to your code behind.
这篇关于获取使用ASP.net C#从HTML选择列表中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文