title: how to create dynamic textbox dropdown list in asp.net
body: <p>I want to create dynamic 2 textbox and 2 dropdownlist below each textbox and dropdownlist in button click.
   This is the code i am using which creates dynamic textbox and dropdownlist but its creating control in  horizontal way.I want creation of dynamic controls in a vertical manner which will be coming under textbox and dropdown.   </p>
  
  <pre><code> &lt;div id="dvContainer" runat="server"&gt;
  
   &lt;table align="center" cellpadding="0" cellspacing="0" width="90%"&gt;
      &lt;tr&gt;
      &lt;td&gt;
          &lt;table width="100%"&gt;
              &lt;tr&gt;
                  &lt;td align="center"&gt;Date&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="TextBox1" runat="server" Width="150px"&gt;              &lt;/asp:TextBox&gt;
                  &lt;/td&gt;
                  &lt;td align="center"&gt;Time&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="TextBox2" runat="server" Width="150px"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
                  &lt;td align="center"&gt;Godown&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:DropDownList ID="DropDownList1" runat="server" Width="150px"&gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
  
   &lt;tr&gt;
      &lt;td&gt;&lt;table width="100%"&gt;
              &lt;tr&gt;
                  &lt;td align="center"&gt;Item&lt;/td&gt;
                  &lt;td align="center"&gt;QTY&lt;/td&gt;
                  &lt;td align="center"&gt;Unit&lt;/td&gt;
                  &lt;td align="center"&gt;Available&lt;/td&gt;
                  &lt;td align="center"&gt;&lt;/td&gt;
  
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="center"&gt;
                      &lt;asp:DropDownList ID="DropDownList2" runat="server" Width="150px"&gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/td&gt;
                  &lt;td align="center"&gt;
                      &lt;asp:TextBox ID="TextBox3" runat="server" Width="150px"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
                  &lt;td align="center"&gt;
                      &lt;asp:DropDownList ID="DropDownList3" runat="server" Width="150px"&gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/td&gt;
                  &lt;td align="center"&gt;
                      &lt;asp:TextBox ID="TextBox4" runat="server" Width="150px"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
                   &lt;td align="center"&gt;
                       &lt;asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /&gt;
                  &lt;/td&gt;
  
              &lt;/tr&gt;
  
          &lt;/table&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
  &lt;/table&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the code i am using in cs page</p>
  
  <pre><code>public partial class StockEntry : System.Web.UI.Page
  {
      protected System.Web.UI.WebControls.DropDownList Ddl_Item;
      protected System.Web.UI.WebControls.TextBox Txt_Quantity;
      protected System.Web.UI.WebControls.DropDownList Ddl_Unit;
      protected System.Web.UI.WebControls.TextBox Txt_Available;
  
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
  
      int countTimes = 0;
  
      protected void Button1_Click(object sender, EventArgs e)
      {
          if (ViewState["countTimes"] == null)
          {
              countTimes = 1;
          }
          else
          {
              countTimes = Convert.ToInt32(ViewState["countTimes"]);
          }
  
          for (int i = 0; i &lt; countTimes; i++)
          {
              Ddl_Item = new DropDownList();
              Ddl_Item.ID = "Ddl_Item" + i;
              Ddl_Item.Width = 180 + i;
  
              Txt_Quantity = new TextBox();
              Txt_Quantity.ID = "Txt_Quantity" + i;
              Txt_Quantity.Width = 180 + i;
  
              Ddl_Unit = new DropDownList();
              Ddl_Unit.ID = "Ddl_Unit" + i;
              Ddl_Unit.Width = 180 + i;
  
              Txt_Available = new TextBox();
              Txt_Available.ID = "Txt_Available" + i;
              Txt_Available.Width = 180 + i;
  
              dvContainer.Controls.Add(Ddl_Item);
              dvContainer.Controls.Add(Txt_Quantity);
  
              dvContainer.Controls.Add(Ddl_Unit);
              dvContainer.Controls.Add(Txt_Available);
  
          }
          countTimes = countTimes + 1;
  
          ViewState.Add("countTimes", countTimes);
      }
  }
  </code></pre>