title: Populate a number of DropDownLists with MySQL reader
body: <p>I have 10 DropDownLists (ddlQuestion1IDs, ddlQuestion2IDs, ddlQuestion3IDs...) that I want to populate with data from a database.  However, the following code only populates ddlQuestion1IDs.  Why is this and what's the most efficient way to populate all 10 with the same data?</p>
  
  <pre><code>protected void getQuestionIDs()
  {
      string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
      MySqlConnection conn = new MySqlConnection(connStr);
      MySqlDataReader reader;
  
      string cmdText = "SELECT * FROM questions WHERE module_id=@ModuleID";
      MySqlCommand cmd = new MySqlCommand(cmdText, conn);
      cmd.Parameters.Add("@ModuleID", MySqlDbType.Int32);
      cmd.Parameters["@ModuleID"].Value = ddlModules.SelectedValue;
  
      try
      {
          conn.Open();
          reader = cmd.ExecuteReader();
          for (int i = 1; i &lt;= 10; i++)
          {
              var ddlQuestion = (DropDownList)FindControl("ddlQuestion" + i.ToString() + "IDs");
              ddlQuestion.DataSource = reader;
              ddlQuestion.DataValueField = "question_id";
              ddlQuestion.DataTextField = "question_id";
              ddlQuestion.DataBind();
              ddlQuestion.Items.Insert(0, new ListItem(string.Empty, "blank"));
          }
          reader.Close();
      }
      catch
      {
          lblError.Text = "Database connection error - failed to get question IDs.";
      }
      finally
      {
          conn.Close();
      }
  }
  </code></pre>