简体   繁体   English

在ASP.NET中使用RequiredFieldValidator的DropdownList值

[英]DropdownList Values using RequiredFieldValidator in ASP.NET

How to select any specific value from dropdownlist. 如何从下拉列表中选择任何特定值。 Currently have YES and NO . 目前有YES和NO。 If No is selected then should show an error message using Required Field Validator. 如果选择否,则应该使用必填字段验证器显示错误消息。 There should be no error message when the value is selected as YES from dropdown 从下拉列表中选择“是”时,应该没有错误消息

You can set the InitialValue of the RequiredFieldValidator to NO (if the value is the same as the text, otherwise use the appropriate value): 您可以将RequiredFieldValidatorInitialValue设置为NO (如果该值与文本相同,否则使用适当的值):

<asp:asp:RequiredFieldValidator ID="ReqYesNo" runat="server" 
    ControlToValidate="DropDownListYesNo"
    InitialValue="NO">
</asp:RequiredFieldValidator>

add the value on which you want to show error message in InitialValue property of required field. 在必填字段的InitialValue属性中添加要在其上显示错误消息的值。

like this - 像这样 -

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="you have selected NO" ControlToValidate="YOURDropDownID" InitialValue="NO"></asp:RequiredFieldValidator>

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

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