我正在尝试从html选择选项中获取我选择的值/文本,但我无法获取它!我已经尝试过在此网站上发布的答案,但没有任何效果。
这是我的代码:
<select id="Select" name="Select" runat="server">
<option value="1">Option 1</option>
</select>
我尝试了以下C#代码:
string name = nombre.Items[nombre.SelectedIndex].Text; //With this I get Index out of range error message.
string name = this.nombre.Value.ToString(); //With this I get nothing
string name = this.nombre.Value; //Nothing here
我能做什么?使用html select控件是必要的。
获得价值,
string sVal = dropdownName.Items[dropdownName.SelectedIndex].Value;
得到一个文本,
string sText= dropdownName.Items[dropdownName.SelectedIndex].Text;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句