title: Populating a drop down list dynamically in ASP.net, and passing that value to another query?
body: <p>2 questions for everybody.</p>
  
  <p>1) How can I order the years by their value, it crashes when I use DESC?</p>
  
  <p>2) If I populate my list like so:</p>
  
  <pre><code> string strConn = ConfigurationManager.ConnectionStrings["rde_410978ConnectionString"].ToString();
      SqlConnection con = new SqlConnection(strConn);
      SqlCommand cmd = new SqlCommand();
      cmd.Connection = con;
      cmd.CommandType = CommandType.Text;
      cmd.CommandText = "Select Distinct Year from MonthlySales DESC"; //DESC DOESNT WORK?
  
      DataSet objDs = new DataSet();
      SqlDataAdapter dAdapter = new SqlDataAdapter();
      dAdapter.SelectCommand = cmd;
      con.Open();
      dAdapter.Fill(objDs);
      con.Close();
  
      if (objDs.Tables[0].Rows.Count &gt; 0)
      {
          ddItems.DataSource = objDs.Tables[0];
          ddItems.DataTextField = "Year";
          ddItems.DataValueField = "Year";
          ddItems.DataBind();
          ddItems.Items.Insert(0, "Select");
      }
  </code></pre>
  
  <p>How can I make the year selected appear under ddItems.SelectedItem?</p>
  
  <pre><code>WHERE Year = " + ddItems.SelectedItem + "GROUP BY Name ";
  </code></pre>
  
  <p>That part of another query doesn't work when I populate my list dynamically, any reasons why/ how can I fix it.</p>
  
  <p>Regards.</p>
  
  <p>EDIT:
  To make my second question clearer, after debugging its always selecting the top item in the drop down list not the actual selected item?</p>