Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8359961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:18:56+00:00 2026-06-09T11:18:56+00:00

I have a form in which I have a ComboBox control with two values.

  • 0

I have a form in which I have a ComboBox control with two values.

Once the user selects one item in the list, I need to display a table of data corresponding to the option selected.

if (DropDownList1.SelectedValue == 1) 
{ 
    // open a SqlCommand
    // read values 
    // fill table
}
else if (DropDownList1.SelectedValue == 2)     
{ 
     // etc

The problem is that I only want to fill the table after the user makes a selection. But when the form is loaded the ComboBox automatically chooses the first option and my code runs, filling the table.

How do I prevent this from happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:18:58+00:00Added an answer on June 9, 2026 at 11:18 am

    what did you try so far?

    there is no problem in having the table name coming from a DropDown, it’s more about understanding and designing the Data Access layer for your application. Do you have a save button in your WebForm and are you composing the SQL code dynamically in the code behind or using stored procedures?

    starting point to connect to SQL Server and execute a command is generally similar to the following (if you do not use ORM like Entity Framework):

    using (varconn = new SqlConnection(connectionString)) 
    using (var cmd = conn.CreateCommand(...)))
    { 
        conn.Open();
    
        cmd.ExecuteNonQuery();
    }
    

    if you need more ideas about how to use EF (or simply a DAL technique) with ASP.NET (MVC or Web Forms), see my answer here: https://stackoverflow.com/a/7474357/559144

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one combobox on the window form and I have one method which
I would like to have a ComboBox control on a form which will be
I have a parent form, which contains panels that calls different user control. For
I have an Excel2010 VBA userform that has one comboBox, from which the user
I have a maximized form which has Combo-Box control (docked in top-right) with 500px
I have a form which has a Combo Box Control. I have selected the
I have this form, in which i need to populate a combo box with
On a form, I have two combobox wich have the same DataSource (their elements
I have a datagrid control in my project which has a combobox control manually
I have a form which contains infinite number of options which user and add.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.