Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would advocate Kyra's first solution to modify the dropdown lists so that the same value cannot be selected, it is always better to prevent problems than tell the user what they did was wrong. However, if you do want to use a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx" rel="nofollow noreferrer">CustomValidator</a> the following code would work:</p> <pre><code>&lt;asp:CustomValidator ID="dropDownValidation" runat="server" OnServerValidate="dropDownValidation_ServerValidate" ErrorMessage="The same value cannot be selected in more than one drop down." /&gt; </code></pre> <p>And then in the code behind, or a script tag.</p> <pre><code>protected void dropDownValidation_ServerValidate(object sender, ServerValidateEventArgs e) { e.IsValid = !haveSameValue(DropDownList1.SelectedValue, DropDownList2.SelectedValue) &amp;&amp; !haveSameValue(DropDownList1.SelectedValue, DropDownList3.SelectedValue) &amp;&amp; !haveSameValue(DropDownList1.SelectedValue, DropDownList4.SelectedValue) &amp;&amp; !haveSameValue(DropDownList2.SelectedValue, DropDownList3.SelectedValue) &amp;&amp; !haveSameValue(DropDownList2.SelectedValue, DropDownList4.SelectedValue) &amp;&amp; !haveSameValue(DropDownList3.SelectedValue, DropDownList4.SelectedValue); } protected bool haveSameValue(string first, string second) { if (first != null &amp;&amp; second != null) { return first.Equals(second); } return first == null &amp;&amp; second == null; } </code></pre> <p>This can obviously be further refined, and a javascript function can be used to provide client side validation if desired using the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.clientvalidationfunction.aspx" rel="nofollow noreferrer">ClientValidationFunction</a> property.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload