title: Retrieve value from dynamic dropdownlist in placeholder C#
body: <p>I have dynamic drop down lists that are created based on what's selected in the list box.. When clicking confirm this is when the drop down lists are created. Clicking save is where I attempt to retrieve the values. However I am unable to retrieve that values that are in the drop down lists. </p>
  
  <p>Code:</p>
  
  <pre><code>protected void btnConfirm_Click(object sender, EventArgs e)
  {
      int ID = 0;
      foreach (string value in values)
      {
          MyStaticValues.alEdit.Add(value);
          CreateEditForm(value, ID);
          ID += 1;
     }
     if (values.count != 0)
     {
          btnSave.Visible = true;
          btnConfirm.Enabled = false;
     }
  }//End of btnConfirm_Click
  
  protected void CreateEditForm(string Value, int ID)
  {//Creates an edit form for the value inserted.
      string name = value;
  
      //This part adds a header
      phEditInventory.Controls.Add(new LiteralControl("&lt;h2&gt;" + name + "&lt;/h2&gt;"));
      phEditInventory.Controls.Add(new LiteralControl("&lt;div class=\"clearfix\"&gt;&lt;/div&gt;"));
  
      //Create a label
      Label lblName = new Label();
      lblName.Text = "Name";
      lblName.ID = "lblName" + ID;
      lblName.CssClass = "control-label";
  
      //Create a Drop Down List
      DropDownList ddlName = new DropDownList();
      ddlName.ID = "ddlName" + ID;
      ddlName.CssClass = "form-control";
  
      //Set default N/A Values For Drop Down List
      ddlName.Items.Add(new ListItem("N/A", Convert.ToString("0")));
  
      //The Rest of the Values are populated with the database
  
      //Adds the controls to the placeholder
      phEditInventory.Controls.Add(lblName);
      phEditInventory.Controls.Add(ddlName);
      phEditInventory.Controls.Add(new LiteralControl("&lt;div class=\"clearfix\"&gt;&lt;/div&gt;"));
  } //End of CreateEditForm
  
  protected void btnSave_Click(object sender, EventArgs e)
  {
      string name = "";
  
      try
      {
          for (int i = 0; i &lt; MyStaticValues.alEdit.Count; i++)
          {
              string nameID = "ddlName" + i.ToString();
              DropDownList ddlName = (DropDownList)phEditInventory.FindControl(nameID);
              name = ddlName.SelectedValue.ToString();
           }
       }
       catch (Exception ex)
       {
       }
  
       phEditInventory.Visible = false;
       btnSave.Visible = false;
       MyStaticValues.alEdit.Clear();
  }//End of btnSave_Click Function
  </code></pre>