2016-06-28 208 views
0

我想问一下,如何比较2下拉列表值,以便它们不能相同。 <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Text="Kuala Lumpur International Airport" Value="KUL"></asp:ListItem> <asp:ListItem Text="Kota Kinabalu International Airport" Value="BKI"></asp:ListItem> <asp:ListItem Text="Penang International Airport" Value="PEN"></asp:ListItem> </asp:DropDownList>验证2下拉列表

`<asp:DropDownList ID="DropDownList2" runat="server"> 
    <asp:ListItem Text="Kuala Lumpur International Airport" Value="KUL"></asp:ListItem> 
    <asp:ListItem Text="Kota Kinabalu International Airport" Value="BKI"></asp:ListItem> 
    <asp:ListItem Text="Penang International Airport" Value="PEN"></asp:ListItem> </asp:DropDownList>` 

我怎么做,这样,2个值将是不一样的。就像用户在DropDownList1中选择吉隆坡国际机场一样,他们无法在DropDownList2中选择吉隆坡国际机场。 感谢大家的帮助。 :)

+0

,获得该项目,并从dropdownlist2禁用该项目。 –

+0

嗨。 Sowjanya。感谢您的回复。有可能的?如果可能的话,我该怎么做? –

+0

请参阅http://www.c-sharpcorner.com/forums/how-do-disable-a-combobox-item-in-win-form-using-c-sharp。它可能会帮助你。 –

回答

1

如果用户选择从dropdownlist1一个项目可以使用CompareValidator

<asp:CompareValidator ID="Validator" 
     runat="server" 
     ControlToValidate="DropDownList1" 
     ControlToCompare="DropDownList2" 
     ErrorMessage="Please select a different airport." 
     Type="String" 
     Operator="NotEqual"/> 
+0

嗨。阿尔文。感谢您的回复。我想问一下,我可以用相同的方式进行日期吗? –

+0

@ CAP2100APR2016是的,你可以。 – Kahbazi

+0

谢谢阿尔文。非常感谢你。 –