3 way to validate this problem
1. Using Server Side code (C#, VB)
if(dropdownList1.SelectedValue=="")
{
lblMessage.Text="Please Select Your City.";
return;
}
2. Using RequiredFieldValidator
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Male"></asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please Select City" ControlToValidate="DropDownList1"
ForeColor="Red"></asp:RequiredFieldValidator>
3. Using JavaScript
<script type="text/javascript">
function CheckDropDownList() {
if (document.getElementById('DropDownList1').selectedIndex = "0")
alert('Please Select City');
}
</script>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="CheckDropDownList()" />
learn about validation control please visit
http://msdn.microsoft.com/en-us/library/aa479013.aspx[
^]
Thanks