简体   繁体   中英

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

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.

(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. The issue is with your HTML markup

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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