Link to home
Start Free TrialLog in
Avatar of dwezil
dwezilFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How can I make a message box pop up if no selection is made from a dropdown list but the submit button is clicked.

I need to make a message box pop up if a user doesnt select anything from my ddl but clicks the submit button. Id like my statement to stop wokring at this point too. Any help would be superb, thanks!
protected void btnSubmit_Click(object sender, EventArgs e)
    {
 
 
 
 
 
 
 
        string connectionString = "Server = *****;Database =****;User ID =*****;Password=********;Trusted_Connection = False; MultipleActiveResultSets=True" ;
 
        SqlConnection myConnection = new SqlConnection(connectionString);
        myConnection.Open();
 
 
        string EngineerID=null;
 
        string commandString1 = "SELECT EngineerID FROM tblNewCategory Where Category like '" + ddlCategory.SelectedValue + "'";
 
        SqlCommand myCommand1 = new SqlCommand(commandString1, myConnection);
 
        SqlDataReader myReader1 = myCommand1.ExecuteReader();
        myReader1.Read();
 
        if (myReader1.HasRows)
        {
            EngineerID = myReader1.GetInt16(0).ToString();
 
        }
 
        myReader1.Close();

Open in new window

Avatar of Binuth
Binuth
Flag of India image


protected void btnSubmit_Click(object sender, EventArgs e)
    {
 
 
 if (comboBox1.SelectedIndex == -1)
			{
				MessageBox.Show("please select");
				return;
			}
 
 
 
 
        string connectionString = "Server = *****;Database =****;User ID =*****;Password=********;Trusted_Connection = False; MultipleActiveResultSets=True" ;
 
        SqlConnection myConnection = new SqlConnection(connectionString);
        myConnection.Open();
 
 
        string EngineerID=null;
 
        string commandString1 = "SELECT EngineerID FROM tblNewCategory Where Category like '" + ddlCategory.SelectedValue + "'";
 
        SqlCommand myCommand1 = new SqlCommand(commandString1, myConnection);
 
        SqlDataReader myReader1 = myCommand1.ExecuteReader();
        myReader1.Read();
 
        if (myReader1.HasRows)
        {
            EngineerID = myReader1.GetInt16(0).ToString();
 
        }
 
        myReader1.Close();

Open in new window

sorry last comment is realted to windows app ... not for web
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dwezil

ASKER

Spot on mate cheers!