I have two dropdowns with same list populated from database . I want to validate where dropdown 1 value is not same as dropdown 2 . Thanks SmartDev
If you want to stay in the asp.net world use a CompareValidator using Operator="NotEqual"
like this:
<asp:CompareValidator id="Compare1" runat="server"
ControlToValidate="DropDown1"
ControlToCompare="DropDown1"
EnableClientScript="True"
Operator="NotEqual"
ErrorMessage="Duplicate selection detected"/>
ASP.Net comes with a whole suite of validator controls. A quick look at them is all you really need to find out how to do this.
<asp:CompareValidator id="valCompare" runat="server"
ControlToValidate="dropdown1"
ControlToCompare="dropdown2"
Operator="NotEqual"
ErrorMessage="* You must enter different values into the dropdownboxes"
Display="dynamic">*
</asp:CompareValidator>
if (ddl1.SelectedValue != ddl2.SelectedValue)
{
//different
}
else
{
//same
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.