Form Validate Pulldown  (RequiredFieldValidator)

Posted on 2006-03-21
Last Modified: 2008-02-20
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>
Question by:net_susan
    LVL 17

    Expert Comment

    use an compare validator whit the comparevalue=0 and the operator=greatherthan
    LVL 17

    Assisted Solution

    <asp:CompareValidator id="cv" runat="server" Operator="GreaterThan" ValueToCompare="0" Type="Integer"
          ErrorMessage="Valor requerido" ControlToValidate="Food Type" cssclass="Error"></asp:CompareValidator>
    LVL 10

    Accepted Solution

    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"/>
    LVL 1

    Author Comment

    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>      

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now