title: How to pull data from database and display in dropdownlist
body: <p>I want to display details of a receipt number when the user enters the number and do a search. After the user should be able to edit the details. I pull the information for the driver; however, when I click to edit the list of drivers from the database is not shown; but just the actual data.</p>
  
  <pre><code>private void BindData()
  
  {
      int parsedValue;
  
      DataTable dt = new DataTable();
      SqlCommand cmd = new SqlCommand();
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.CommandText = "PP_spSearchReturnCrate";
      if (!string.IsNullOrEmpty(txtReceiptNo.Text.Trim()))
      {
          cmd.Parameters.Add("@receiptNo", SqlDbType.VarChar).Value = txtReceiptNo.Text.Trim();
      }
      cmd.Connection = sqlConn;
      sqlConn.Open();
      SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
      sqlDa.Fill(dt);
  
  
  
      if (dt.Rows.Count &gt; 0)
      {
  
  
  
          String DATE = Convert.ToDateTime(dt.Rows[0]["returnDte"]).ToString("yyyy-MM-dd");
          txtReturnDte.Text = DATE;
          txtReceipt.Text = dt.Rows[0]["receiptNo"].ToString(); //Where ColumnName is the Field from the DB that you want to display
          ddlCustomer.Text = dt.Rows[0]["CUSTNAME"].ToString();
  
          //ddlDriver.Text = dt.Rows[0]["driverName"].ToString();
          //ListItem lis = new ListItem(dt.Rows[0]["driverName"].ToString());
          //ddlDriver.Items.Add(lis);
          ddlUnitId.Text = dt.Rows[0]["unitId"].ToString();
          txtNumber.Text = dt.Rows[0]["qtyReturned"].ToString();
          txtLocation.Text = dt.Rows[0]["custLocation"].ToString();
          //ddlDriver.DataSource = cmd.ExecuteReader();
          //ListItem lis = new ListItem(dt.Rows[0]["driverName"].ToString());
          //ddlCustomer.Items.Add(lis);
          ddlDriver.DataSource = dt;
          ddlDriver.DataBind();
          ddlDriver.DataTextField = "driverName";
          ddlDriver.DataValueField = "driverName";
          ddlDriver.DataBind();
          //ListItem li = new ListItem(dt.Rows[0]["driverName"].ToString());
          //ddlDriver.Items.Add(li);
          Panel1.Visible = true;
  
      }
  }
  </code></pre>