2 个下拉菜单上的 asp CompareValidator
场景:
我有以下控件:
<telerik:RadComboBox ID="dd1" runat="server" ValidationGroup="g1" InitialValue="-1" />
<telerik:RadComboBox ID="dd2" runat="server" ValidationGroup="g1" InitialValue="-1" />
<asp:CompareValidator ID="cv" runat="server" ValidationGroup="g1" InitialValue="-1"
ControlToValidate="dd1" ControlToCompare="dd2" Operator="NotEqual" Text="error"
Type="String" />
我不希望 2 个下拉菜单具有相同的值,不包括“-1”(任何下拉菜单的默认值)。
我可以使用compareValidator 来实现这一点吗?或者我应该使用javascript?
提前致谢
Scenario:
I have the following controls:
<telerik:RadComboBox ID="dd1" runat="server" ValidationGroup="g1" InitialValue="-1" />
<telerik:RadComboBox ID="dd2" runat="server" ValidationGroup="g1" InitialValue="-1" />
<asp:CompareValidator ID="cv" runat="server" ValidationGroup="g1" InitialValue="-1"
ControlToValidate="dd1" ControlToCompare="dd2" Operator="NotEqual" Text="error"
Type="String" />
I don't want the 2 dropDowns to have the same values, excluding "-1" which is the default value of any dropdown.
Can I achieve this using the compareValidator? or should i use javascript?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了比较,比较验证器是正确的。但对于初始值 (-1),您需要为两个下拉列表添加必需的字段验证器。所以用户必须选择值。
For comparision, compare validator is correct. But for initial value (-1), you need to add required field validators for both dropdowns. So user must select value.
单个 CompareValidator 本身无法满足您的需要,但您可以将另一个 CompareValidator 添加到您的设置中。典型的 ASP.NET DropDownList 如果为空则没有默认值。它基于列表中的第一项。我不确定您使用的 telerik 控件是否有默认值 -1,但如果有,那么您可以为每个下拉列表添加一两个 CompareValidators 并设置 ValueToCompare 属性,然后检查 NotEqual:
A single CompareValidator by itself will not do what you need, but you can just add another CompareValidator to your setup there. A typical ASP.NET DropDownList doesn't have a default value if empty. It's based on the first item in the list. I'm not sure if the telerik controls you are using have a default value of -1, but if they do, then you could add one or two CompareValidators for each dropdown and set the ValueToCompare attribute, and check for NotEqual: