【问题标题】:Getting the selected value of a combo box in server side在服务器端获取组合框的选定值
【发布时间】:2012-06-28 07:19:42
【问题描述】:

我的查询是,我的表单中有一个 html 组合框,我想将组合框的选定项的值传递给服务器端,它是一个 aspx 页面,

<form method="POST" action="page.aspx">
    <input id="customerName" name="customerName" type="Text" />
    <input id="customerPhone" name="customerPhone" type="Text" />
    <select id="combobox" >
        <option>df</option>
        <option>as</option>
    </select>
    <input 
</form>
value="Save" type="Submit" />

在服务器端,我使用以下代码集来选择文本框值

string n = String.Format("{0}", Request.Form['customerName']);

但是如何获取组合框选中值的值 请帮我 提前谢谢

【问题讨论】:

  • 请检查您将获得 selectedValue Request.Form['customerName']
  • 你的选择元素需要一个名字; Request.Form 与 name 属性无关。添加一个名称,如 name="MyComboBox",然后 Request.Form["MyComboBox"] 应该为您提供值。出于兴趣,为什么不使用

标签: c# javascript asp.net html


【解决方案1】:

您可以尝试修复您的 html:

<form method="POST" action="page.aspx">
    <input id="customerName" name="customerName" type="text">
    <input id="customerPhone" name="customerPhone" type="text">
    <select id="combobox" name="combobox">
        <option value="df">df</option>
        <option value="as">as</option>
    </select>
    <input value="Save" type="submit">
</form>

选定的值将发布为Request.Form['combobox']

【讨论】:

    猜你喜欢
    • 2013-08-15
    • 2011-10-17
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    相关资源
    最近更新 更多