Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
try
{
  con.Open();
  ddlCountry.DataSource = cmd.ExecuteReader();
  ddlCountry.DataTextField = "CountryName";
  ddlCountry.DataValueField = "ID";
  ddlCountry.DataBind();

  if (ddlCountry.Items.Count > 1)
  {
    ddlCountry.Enabled = true;
  }
  else
  {
    ddlCountry.Enabled = false;
    ddlCity.Enabled = false;
  }
}
Posted
Updated 26-Jan-15 22:05pm
v2
Comments
Kornfeld Eliyahu Peter 27-Jan-15 4:06am    
What is your question?
nagendrathecoder 27-Jan-15 4:12am    
Your question is not clear. Please it a bit more.
krishna97 27-Jan-15 4:21am    
ddlCountry.Items.Count > 1
then given validation Please Select the value..!!1
nagendrathecoder 27-Jan-15 4:31am    
We generally fire a validation on sumbit click.
Is there any specific reason you want validation to fire as soon as list is populated?

1 solution

With your Question/comments I understood that you want to fire the validation message when ever the ddl count is more than 1.

So what i can suggest is to fire the validation messages we generally use Page.Isvalid() and these can fire the messages too.

you can use these method whenever the method is executing or in you can place in the ddl item change event.

If none of the point's mentioned above doesn't helps to your question please elaborate your question with the scenario & requirements.
 
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