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 8458717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:09:17+00:00 2026-06-10T13:09:17+00:00

I have a DropDownList populated from a Database. When I select an item in

  • 0

I have a DropDownList populated from a Database.

When I select an item in the DropDownList, I want to call a procedure and pass the value of the DropDownList to the calling procedure to query a database to populate a couple of Text Boxes.

How to do this?

Code for procedure:

protected void PopulateTextBoxes()
{
    SqlDataReader MyReader;
    SqlConnection Conn;
    SqlParameter TourIdParam;

    string strConnection = ConfigurationManager.ConnectionStrings["ChinatowndbConnString"].ConnectionString;

    Conn = new SqlConnection(strConnection);

    SqlCommand MyCommand = new SqlCommand();

    MyCommand.CommandText = "SELECT TourId, TName, TDetails FROM Chinatowndb.dbo.Tour Where TourId = @TourIdp";
    MyCommand.CommandType = CommandType.Text;
    MyCommand.Connection = Conn;

    TourIdParam = new SqlParameter();
    TourIdParam.ParameterName = "@TourIdp";
    TourIdParam.SqlDbType = SqlDbType.Int;
    TourIdParam.Direction = ParameterDirection.Input;
    TourIdParam.Value = ddlTour.SelectedItem.Value;

    MyCommand.Parameters.Add(TourIdParam);

    MyCommand.Connection.Open();
    MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection);

    while (MyReader.Read())
    {
        tbTourName.Text = (string)MyReader["TName"];
        tbTourDetails.Text = (string)MyReader["TDetails"];
        lblTourId.Text = Convert.ToString(MyReader["TourId"]);
    }
}

Code to populate DropDownBox:

private void PopulateTour()
{

    DataTable dtTour = new DataTable();

    string strConnection = ConfigurationManager.ConnectionStrings["ChinatowndbConnString"].ConnectionString;

    using (SqlConnection con = new SqlConnection(strConnection))
    {

        try
        {
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT TourId, TName FROM Chinatowndb.dbo.Tour", con);
            adapter.Fill(dtTour);

            ddlTour.DataSource = dtTour;
            ddlTour.DataValueField = "TourId";
            ddlTour.DataTextField = "TName";
            ddlTour.DataBind();
        }
        catch (Exception ex)
        {
            // Handle the error
        }

    }

    // Add the initial item
    ddlTour.Items.Insert(0, new ListItem("<Select Tour>", "0"));
}
  • 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-10T13:09:19+00:00Added an answer on June 10, 2026 at 1:09 pm

    You need to add the event handler for the selection change in your HTML

    <asp:DropDownList id="ddlTour"
         AutoPostBack="True"
         OnSelectedIndexChanged="ddlTour_SelectedIndexChanged"
         runat="server">
    

    and process the event in your code behind

      void ddlTour_SelectedIndexChanged(Object sender, EventArgs e)
      {
            // Call the method that gets the current item from the dropdown and fills the textboxes
            PopulateTextBoxes();
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdownlist that is being populated from a database. That is working
On my page I have a DropDownList which I populate with database values from
I have a DropDownList populated from a LINQ query. As per the design requirements
i have a dropdownlist that populates from the sql server database. populating the list
I have DropDownList with CascadingDropDown extender. If I want to retrieve data from the
Basically, I have populated a dropdown list using php from a database on a
my dropdownlist is populated from the database as in: DataTable dt = GetData(); ddlMylist.DataSource
I have a DropDownList that is populated from a datasource. After it is bound,
I have a DropDownList populated with a SelectList generated from (an anonymous type) that
I have a dropdown in my CreateDocumentTemplate ciew <%=Html.DropDownList(Part, (SelectList)ViewData[Part])%> which is populated from

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.