如何避免在下拉列表中“请选择”作为数据? [英] how to avoid 'please select' in dropdown list to consider as data?

查看:86
本文介绍了如何避免在下拉列表中“请选择”作为数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下拉列表中我有使用列表项。在列表项中我必须在第一个列表项中添加''请选择'',这不会被视为数据。那么如何做到这一点?

解决方案

< pre lang =html> < 选择 name = 下拉列表 < span class =code-attribute> id = 下拉菜单 >
< 选项 value = 已选择 已停用 > 请选择< / option >
< 选项 value = value1 > 值1 < / option >
< 选项 value = value2 > 值3 < / option >
< / select >





请注意禁用的属性。浏览器不应允许选择此项。但是,如果,您可以检查代码(在客户端和/或服务器上)空值。


我认为在验证 DropDownList 你遇到了问题,对吧?如果是,则转到 RequiredFieldValidator 控件,用于验证 DropDownList 并设置 RequiredFieldValidator 的I​​nitialValue 请选择。如果您从 DropDownList 中选择请选择项目,并确保该列表项的值为,这将避免您的选择请选择



查看更多信息在这里 [ ^ ]。





--Amit


hi,



 <  选择   名称  = 下拉列表    id   = 下拉菜单 >  
< 选项 value = - 1 > 请选择< / option & gt;
< 选项 value = value1 > 值1 < / option >
< 选项 value = value2 > 值3 < / option >
< / select





使用带有初始值= -1的asp必填字段验证器来限制用户选择请选择。


in dropdown list i have use list item. in list item i have to put ''please select'' at first list item and this will not be consider as data.then how to do this?

解决方案

<select name="dropdown" id="dropdown">
 <option value="" selected disabled>Please select</option>
 <option value="value1" >Value 1</option>
 <option value="value2" >Value 3</option>
</select>



Please note the disabled attribute. Browsers should not allow this to be selected. But if, you can check in code (either on client side and/or server) the empty value.


I think while validating the DropDownList you are getting problem, right? If yes then go to the RequiredFieldValidator controls, which you are using to validate the DropDownList and set the InitialValue of the RequiredFieldValidator as "please select" . This will avoid your selection if you have selected "please select" item from your DropDownList and make sure the value for that listitem is "please select".

Check more referances Here[^].


--Amit


hi,

<select name="dropdown" id="dropdown">
 <option value="-1">Please select</option>
 <option value="value1" >Value 1</option>
 <option value="value2" >Value 3</option>
</select



Use asp required field validator with "initial value=-1", to restrict user to select "please select".


这篇关于如何避免在下拉列表中“请选择”作为数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆