title: Populate a couple of TextBoxes based on selection of a DropDownList
body: <p>I have a <code>DropDownList</code> populated from a Database.</p>
  
  <p>When I select an item in the <code>DropDownList</code>, 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.</p>
  
  <p>How to do this?</p>
  
  <p>Code for procedure:</p>
  
  <pre><code>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></pre>
  
  <p>Code to populate <code>DropDownBox</code>:</p>
  
  <pre><code>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("&lt;Select Tour&gt;", "0"));
  }
  </code></pre>