title: Dynamically adding a DropDownList
body: <p>I am trying to add a dropdown dynamically. 
  No errors except that I don't see the dropdown 
  Here's the code: </p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      if(Ispostback)
      {
          DropDownList ddlPercent = new DropDownList();
          ddlPercent .ID = "ddlDiscountPercent";
          ddlPercent .AutoPostBack = true;
          Panel1.Controls.Add(ddlPercent );
          ddlPercent .ID = "ddlPercent " + 1;
          ddlPercent .Items.Add(new ListItem("5", "5%"));
          ddlPercent .Items.Add(new ListItem("10", "10%"));
          ddlPercent .Items.Add(new ListItem("15", "15%"));
          ddlPercent .Items.Add(new ListItem("20", "20%"));
          ddlPercent .Items.Add(new ListItem("30", "30%"));
          ddlPercent .Items.Add(new ListItem("50", "50%"));
  
          ddlPercent.SelectedIndexChanged += 
                    new EventHandler(ddlPercent_SelectedIndexChanged);
  
          ContentPlaceHolder cph = 
                    (ContentPlaceHolder)this.Master.FindControl("MainContent");
          cph.Controls.Add(ddlPercent );
          // ddlPercent.SelectedIndex =(Int32) ViewState["ddl_index"];
      }
  }
  
  protected void ddlPercent_SelectedIndexChanged(object sender, EventArgs e)
  {
       DropDownList ComboBox=(DropDownList)sender;
       ViewState["ddl_index"] = ComboBox.SelectedValue;        
  }
  </code></pre>