List
Country unselectedCountry = new Country { CountryCode = "XXX", CountryName = "[Please select]" };
countries.Insert(0, unselectedCountry);
ddCountry.DataSource = countries;
Then, create a RequiredFieldValidator in your aspx file with the following properties:
<asp:RequiredFieldValidator runat="server" ControlToValidate="ddCountry" Display="Dynamic" ErrorMessage="*" InitialValue="XXX" ToolTip="Required">
</asp:RequiredFieldValidator>
It will now validate if the dropdown list has no selected index yet because of the added code.
Happy coding!
No comments:
Post a Comment