• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

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>
0
net_susan
Asked:
net_susan
  • 2
2 Solutions
 
Elvio Lujan.Net Senior DeveloperCommented:
use an compare validator whit the comparevalue=0 and the operator=greatherthan
0
 
Elvio Lujan.Net Senior DeveloperCommented:
<asp:CompareValidator id="cv" runat="server" Operator="GreaterThan" ValueToCompare="0" Type="Integer"
      ErrorMessage="Valor requerido" ControlToValidate="Food Type" cssclass="Error"></asp:CompareValidator>
0
 
Oliver AmayaEntrepeneurCommented:
Hi, you can use a normal RequiredFieldValidator and set its InitialValue property to 0:

<asp:RequiredFieldValidator id="rvFood" runat="server" ControlToValidate="Food Type" InitialValue="0"/>
0
 
net_susanAuthor Commented:
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>      
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now