asp.net验证控件,这个DDL的怎么做?速结~
DropDownList怎么用验证控件?
RequiredFieldValidator(必须字段验证) 用于检查是否有输入值
CompareValidator(比较验证) 按设定比较两个输入
RangeValidator(范围验证) 输入是否在指定范围
RegularExpressionValidator(正则表达式验证) 正则表达式验证控件
CustomValidator(自定义验证) 自定义验证控件
ValidationSummary(验证总结) 总结验证结果
用哪个来验证DropDownList所选的Value不等于 "Please select ";
我想用正则表达式验证,但不知道怎么写,行吗?
------解决方案--------------------javascript可以实现
------解决方案-------------------- <asp:DropDownList ID= "DropDownList1 " runat= "server " Width= "120px ">
<asp:ListItem> Plase Seelct </asp:ListItem>
<asp:ListItem> 1 </asp:ListItem>
<asp:ListItem> 2 </asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID= "RequiredFieldValidator1 " runat= "server " ControlToValidate= "DropDownList1 "
ErrorMessage= "* " InitialValue= "Plase Seelct "> * </asp:RequiredFieldValidator>
------解决方案--------------------同意,也可写正则表达式,不过,没必要
------解决方案--------------------我想到的两种方法,请参考
<asp:DropDownList ID= "DropDownList1 " runat= "server " Width= "120px ">
<asp:ListItem> Plase Seelct </asp:ListItem>
<asp:ListItem> 1 </asp:ListItem>
<asp:ListItem> 2 </asp:ListItem>
</asp:DropDownList>
//方法1:
<asp:RequiredFieldValidator ID= "RequiredFieldValidator1 " runat= "server " ControlToValidate= "DropDownList1 " ErrorMessage= "* " InitialValue= "Plase Seelct "> * </asp:RequiredFieldValidator>
//方法2:
<asp:CompareValidator ID= "CompareValidator1 " Operator= "NotEqual " ValueToCompare= "Plase Seelct " ControlToValidate= "DropDownList1 " runat= "server " ErrorMessage= "* "> * </asp:CompareValidator>
------解决方案-------------------- <asp:RequiredFieldValidator ID= "RequiredFieldValidator1 " runat= "server " ControlToValidate= "DropDownList1 "
ErrorMessage= "* " InitialValue= "Plase Seelct "> * </asp:RequiredFieldValidator>
若是验证空呢? "Plase Seelct "改为 " "?
===================
怎么可能空能? 默认的应该就选择了第一个啊
你第一个是空?
------解决方案-------------------- <asp:DropDownList id= "DropDownList1 " runat= "server ">
<asp:ListItem Value= "abc "> abc </asp:ListItem>
<asp:ListItem Value= "ee "> ee </asp:ListItem>
<asp:ListItem Value= "ac "> ac </asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator id= "RequiredFieldValidator1 " runat= "server " ErrorMessage= "RequiredFieldValidator " ControlToValidate= "DropDownList1 " InitialValue= "abc "> * </asp:RequiredFieldValidator>
设置InitialValue就可以了,InitialValue是初始值
------解决方案--------------------RequiredFieldValidator 是验证dropdownlist的value 因此如果你想要选择 Plase Seelct 项时候提示的话 dropdownlist的please select 项的value设置为空就ok了。