How to add textboxes to table when button is clicked
<p>I want to add a new cell and a TextBox into it when a button is clicked.  But when I click the button  in the current row, its cell and TextBox are removed and new ones are added. </p>

<p><strong>Markup:</strong></p>

<pre><code>&lt;form id="form1" runat="server"&gt;
&lt;div&gt;
    &lt;asp:Panel ID="pnlForTextBoxes" runat="server"&gt;
    &lt;/asp:Panel&gt;
    &lt;asp:DropDownList ID="ddlNumbers" runat="server" Height="16px" Width="143px"&gt;
        &lt;asp:ListItem&gt;1&lt;/asp:ListItem&gt;
        &lt;asp:ListItem&gt;2&lt;/asp:ListItem&gt;
        &lt;asp:ListItem&gt;3&lt;/asp:ListItem&gt;
        &lt;asp:ListItem&gt;4&lt;/asp:ListItem&gt;
        &lt;asp:ListItem&gt;5&lt;/asp:ListItem&gt;
    &lt;/asp:DropDownList&gt;`enter code here`
    &lt;asp:Table ID="myActualTable" runat="server"&gt;
    &lt;/asp:Table&gt;
    &lt;br /&gt;
    &lt;asp:Button ID="cmdAddTextBox" runat="server" Text="Add" OnClick="cmdAddTextBox_Click" /&gt;
&lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p><strong>Code:</strong></p>

<pre><code>protected void cmdAddTextBox_Click(object sender, EventArgs e)
{
    TableRow myRow = new TableRow();
    myRow.ID = "row" + ddlNumbers.SelectedValue.ToString();
    TableCell myCell = new TableCell();
    myCell.ID = "cell" + ddlNumbers.SelectedValue.ToString();
    TextBox myTextBox = new TextBox();
    myTextBox.ID = "txt" + ddlNumbers.SelectedValue.ToString();
    myTextBox.Text = "TextBox number " + ddlNumbers.SelectedValue.ToString();
    myCell.Controls.Add(myTextBox);
    myRow.Cells.Add(myCell);
    myActualTable.Rows.Add(myRow);

    myTextBox.Dispose();
    myCell.Dispose();
    myRow.Dispose();
}
</code></pre>
