Dropdwonlist必需的字段验证器 [英] Dropdwonlist required field validator

查看:150
本文介绍了Dropdwonlist必需的字段验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨先生;

我的webForm中有一个下拉列表,并绑定数据库中的项目。但我无法为drpdownlist制作字段验证器。我知道dropdownlist选择初始值但它不起作用。



请帮帮我;

感谢提前;

这里是我的代码:



hi sir;
I have a dropdownlist in my webForm and bind the items from database. But I unable to make field validator for drpdownlist. I know for dropdownlist to Select initial value but it doesn't work.

please help me;
thanks for advance;
here is my code:

<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"

                                       ControlToValidate="drpclassno" ErrorMessage="Please select class"; ForeColor="Red"

                                       InitialValue="--Select Class--"></asp:RequiredFieldValidator>

推荐答案

<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="drpclassno" ErrorMessage="Please select class" ForeColor="Red" InitialValue="0"></asp:RequiredFieldValidator>





并在绑定下拉列表后写下此代码



DropdownListID.Items.Insert(0,new ListItem(Select家长类别,0));





它会l work



and after binding dropdown write this code

DropdownListID.Items.Insert(0, new ListItem("Select Parent Category", "0"));


It will work


从你用过的验证器中删除分号



ErrorMessage =请选择类;
Remove semicolon from validator you have used in

ErrorMessage="Please select class";


必需字段验证器用于绑定用户不将字段留空...但如果您没有在下拉列表中给出空列表项而不需要验证器,



如果从数据库绑定下拉列表比不允许DB中的任何空行,那么不需要验证,因为所有时间下拉列表都将填充至少有一个项目,



此外,如果您仍想更正问题中给定的Validator代码,请遵循 Masoom Mir提供的解决方案[解决方案2] 以及随之而来的



InitialValue =



即清空白色空间,即可使用..



问候,



:)
Required Field Validator is used to bind user to not leave the field empty... But if you do not give empty list item in drop down list than there is no need for the validator,

If you are binding the Drop Down List from Database than don't allow any empty row in DB, so that no validation is required, because all the time drop down list would be having populated with at least one item,

Further if you still want to correct your given piece of Validator code in Question, than follow the solution provided by Masoom Mir[Solution 2] and along with that put the

InitialValue=" "

i.e. to empty white space,, that will work..

Regards,

:)


这篇关于Dropdwonlist必需的字段验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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