Link to home
Start Free TrialLog in
Avatar of net_susan
net_susan

asked on

Form Validate Pulldown (RequiredFieldValidator)

I want to do an asp:RequiredFieldValidator on the drop down below. How can I make the validator text activate if Food Types's selected value = 0?


<asp:DropDownList runat="server" id="Food Type">

      <asp:ListItem Values="0" Selected="True">Please Select</asp:ListItem>
                                                                  <asp:ListItem Value="1">Chicken</asp:ListItem>
                                                                  <asp:ListItem Value="2">Beef</asp:ListItem>
                                                                  <asp:ListItem Value="3">Fish</asp:ListItem>
                                                                        </asp:DropDownList>
Avatar of Elvio Lujan
Elvio Lujan
Flag of Argentina image

use an compare validator whit the comparevalue=0 and the operator=greatherthan
SOLUTION
Avatar of Elvio Lujan
Elvio Lujan
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of net_susan
net_susan

ASKER

Both ways worked like this:

<asp:CompareValidator id="cv" runat="server" Operator="GreaterThan" ValueToCompare="0" Type="Integer" ControlToValidate="FoodType">Please select your food type!</asp:CompareValidator>

<asp:RequiredFieldValidator ID="rvFood" ControlToValidate="FoodType" Runat="server" InitialValue="0">Please select your food type!</asp:RequiredFieldValidator>