title: Add row dynamically to table in ASP.NET?
body: <p>I'm trying to add rows dynamically to a System.Web.UI.WebControls.Table control in ASP.NET. I found some <a href="http://forums.asp.net/t/1219583.aspx" rel="nofollow noreferrer">sample code</a> that does what I'm seeking, but it only adds a single row. </p>
  
  <p>It seems like the table row count does not carry from one page load to the next. The user should be able to add as many rows as desired, and I need to capture the data from each row.</p>
  
  <p>What am I missing? Code below.</p>
  
  <pre><code>&lt;%@ Page Language="VB" %&gt;
  &lt;script runat="server"&gt;
  
      Sub btnAddEmail_Click(ByVal Sender As Object, ByVal e As EventArgs)
  
          Dim tr As New TableRow
          Dim tcLabel As New TableCell
          Dim tcTextBox As New TableCell
          Dim newLabel As New Label
          Dim newTextBox As New TextBox
  
          Dim i As Integer = Table1.Rows.Count + 1
  
          newLabel.ID = "Email" + Convert.ToString(i)
          newLabel.Text = "Email" + Convert.ToString(i)
  
          newTextBox.ID = "txtEmail" + Convert.ToString(i)
  
          tcLabel.Controls.Add(newLabel)
          tcTextBox.Controls.Add(newTextBox)
  
          tr.Cells.Add(tcLabel)
          tr.Cells.Add(tcTextBox)
  
          Table1.Rows.Add(tr)
  
      End Sub
  
  &lt;/script&gt;
  
  &lt;form id="form1" runat="server"&gt;
  &lt;div&gt;
      &lt;asp:Button runat="server" Text="Add Email" ID="btnAddEmail"
          onclick="btnAddEmail_Click" /&gt;
      &lt;asp:Table ID="Table1" runat="server"&gt;
          &lt;asp:TableRow&gt;
              &lt;asp:TableCell&gt;
                  &lt;asp:Label ID="Email1" runat="server" Text="Email1"&gt;&lt;/asp:Label&gt;&lt;/asp:TableCell&gt;
              &lt;asp:TableCell&gt;
                  &lt;asp:TextBox ID="txtEmail1" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/asp:TableCell&gt;
          &lt;/asp:TableRow&gt;
      &lt;/asp:Table&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>