Click here to Skip to main content
15,902,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the below dropdown if i select value="-1" it will show a message like
Please select a course It should not accept the First value.

ASP.NET
<p>
   <asp:Label ID="lblcourses" runat="server" Text="Course Name"></asp:Label>
   <asp:DropDownList ID="drpcourses" runat="server">
  <asp:ListItem Text="" Value="-1"></asp:ListItem>
   <asp:ListItem Text="Basic Unix" Value="1"></asp:ListItem>
   <asp:ListItem Text="Basic Oracle" Value="2"></asp:ListItem>
   <asp:ListItem Text="PL/SQL" Value="3"></asp:ListItem>
   <asp:ListItem Text="Oracle 11g DBA" Value="4"></asp:ListItem>
   <asp:ListItem Text="Oracle 11g DBA F/T" Value="5"></asp:ListItem>
   <asp:ListItem Text="Oracle 11g RAC F/T" Value="6"></asp:ListItem>
   <asp:ListItem Text="Linux Admin" Value="7"></asp:ListItem>
   <asp:ListItem Text="Unix Administration" Value="8"></asp:ListItem>
   <asp:ListItem Text="Advance Shell" Value="9"></asp:ListItem>
   <asp:ListItem Text="Hadoop Administration" Value="1"></asp:ListItem>
   </asp:DropDownList>
   <asp:RequiredFieldValidator ID="rfvcourses" runat="server" controltovalidate="drpcourses" ErrorMessage="Select a Course"></asp:RequiredFieldValidator>
   </p>

 <p>
 <asp:Button ID="btnsave" runat="server"  Text="Add"/>
 </p>
Posted

you need to add InitialValue="-1"
ASP.NET
<asp:requiredfieldvalidator id="rfvcourses" runat="server" initialvalue="-1" controltovalidate="drpcourses" errormessage="Select a Course"></asp:requiredfieldvalidator>

RequiredFieldValidator.InitialValue Property[^]
 
Share this answer
 
v3
C#
<asp:dropdownlist id="ddlDesignation" runat="server" xmlns:asp="#unknown"></asp:dropdownlist>
                            
                       
<asp:requiredfieldvalidator id="RequiredFieldValidator3" runat="server" controltovalidate="ddlDesignation" xmlns:asp="#unknown">
ErrorMessage="Please select your designation." ValidationGroup="submit" InitialValue="-1" SetFocusOnError="True" CssClass="Validators"></asp:requiredfieldvalidator>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900