DropDownList Must Have a Value Selected Other Than the Default
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" ValidationGroup="DDL">
<asp:ListItem>--Please Select--</asp:ListItem>
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="DropDownList1"
ErrorMessage="DropDownList1 Must Have a Value Selected"
InitialValue="--Please Select--"
SetFocusOnError="True"
ValidationGroup="DDL">*</asp:RequiredFieldValidator><br />
</div>
</form>
</body>
</html>
Related examples in the same category