title: Dynamically add rows to DataTable
body: <p>I have an asp.net form with a textbox and a button. Each time the button is clicked I need the text from the textbox to be added as a new row in a table, which will then be presented on a gridview.</p>
  
  <p>I have managed to add the text from the textbox as a new row, but every time I click the button it seems the table is not saved (meaning - I end up with only one row).</p>
  
  <pre><code>public partial class buildTable : System.Web.UI.Page
  {
          DataTable dt = new DataTable();
          public int namesCounter;
  
  protected void Page_Load(object sender, EventArgs e)
  {
          dt.Columns.Add("ID", typeof(Int16));
          dt.Columns.Add("name", typeof(string));
          namesCounter = 0;
  
          names_GV.DataSource = dt;
  }
  protected void addName_Click(object sender, EventArgs e)
  {
          namesCounter += 1;
          DataRow dtrow = dt.NewRow();
          dtrow["ID"] = namesCounter;
          dtrow["name"] = newName_TXT.Text;
          dt.Rows.Add(dtrow);
          names_GV.DataBind();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I'm guessing this has something to do with postback...</p>