Solved

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

Posted on 2008-10-01
4
194 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:dwezil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Binuth
ID: 22612600

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

0
 
LVL 14

Expert Comment

by:Binuth
ID: 22612605
sorry last comment is realted to windows app ... not for web
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 22612662
Hello dwezil,

btSubmit.Attributes.Add("onclick","if(document.getElementById('ddlCategory').value=='NONE') {window.alert('You must select a category');return false;}");

Add this to your page load and click the button, you may need to have "NONE" as the value for your default selection / or change the above line to reflect your default selection.

Regards,

TimCottee
0
 

Author Closing Comment

by:dwezil
ID: 31501888
Spot on mate cheers!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp.net, radiobuttonlist, c# 3 69
SQL Server Serialization error 8 48
Save data in two Database, Asp 2 71
center div inside another div 2 32
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question