RequiredFieldValidator on DropDownList in ASP.Net

 You can use the RequiredFieldValidator control’s InitialValue property to specify a default value other than an empty string.
The RequiredFieldValidator control includes an InitialValue property. The value of the first list from the DropDownList control is assigned to this property.
Example
  1. <asp:DropDownList id="dropFavoriteColor" Runat="server">  
  2. <asp:ListItem Text="Select Color" Value="none" />  
  3. <asp:ListItem Text="Red" Value="Red" />  
  4. <asp:ListItem Text="Blue" Value="Blue" />  
  5. <asp:ListItem Text="Green" Value="Green" />  
  6. </asp:DropDownList>  
  7.   
  8. <asp:RequiredFieldValidator id="reqFavoriteColor" Text="(Required)" InitialValue="none" ControlToValidate="dropFavoriteColor" Runat="server" /> 
Ebook Download
View all
Learn
View all