• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • 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>
  • 2
2 Solutions
Elvio Lujan.Net Senior DeveloperCommented:
use an compare validator whit the comparevalue=0 and the operator=greatherthan
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>
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"/>
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>      
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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