简体   繁体   English

从ASP.NET代码中的SELECT获取值

[英]Getting Values from SELECT in ASP.NET codebehind

I have the following content: 我有以下内容:

<input type="text" name="val1">
<select name="sel1"><option value="1">one</option><option value="2">two</option></select>

When iterating the formdata using 使用时迭代formdata

Request.Form.Allkeys

Both values (val1 and sel1) are inside the keys-List, but while Form["val1"] has the content I entered in the form, Form["sel1"] is always null. 这两个值(val1和sel1)都在键列表中,但是Form [“ val1”]具有我以表单形式输入的内容,而Form [“ sel1”]始终为null。

(Using server-controls is not an option in this case) (在这种情况下,不能使用服务器控件)

The reason for that is because there is no value. 这样做的原因是因为没有价值。 No value will return null. 没有值将返回null。 The issue is with your HTML markup 问题在于您的HTML标记

<select name="sel1"><option>one</option><option>two</option></select>

Should be 应该

<select name="sel1"><option value="one">one</option><option value="two">two</option></select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM