title: How to extract data from a TextBox to a GridView (multiple rows to be displayed in the GridView)?
body: <p>I have used the following code to display data from a TextBox to a GridView without saving the data to the database(Two TextBoxes and a Button). When I enter the Name and City in the TextBoxes, and click on the Button, those values will be displayed in the Gridview. It is working as expected without any errors. But I want to tweak the code a bit so that the GridView should be able to add new data from the Textbox by retaining the old data as it is in the Gridview (<strong>multiple rows should be displayed in the Gridview</strong> instead of single rows).</p>
  
  <p>It is a <strong>web-based</strong> ASP.NET application using C# coding (Visual Studio 2010).</p>
  
  <p><strong>Can you make the necessary changes to the code given below so as to implement the above functionality?</strong></p>
  
  <pre><code>public partial class _Default : System.Web.UI.Page
  {
      DataSet ds = new DataSet();
      DataTable dt = new DataTable();
  
  protected void Page_Load(object sender, EventArgs e)
      {
  
      }
  
  protected void btnTextDisplay_Click(object sender, EventArgs e)
      {
              DataColumn dc1 = new DataColumn("Name");
              DataColumn dc2 = new DataColumn("City");
              dt.Columns.Add(dc1);
              dt.Columns.Add(dc2);
  
              DataRow dr = dt.NewRow();
              dr[0] = txtName.Text;
              dr[1] = txtCity.Text;
              dt.Rows.Add(dr);
              gvDisplay.DataSource = dt;
              gvDisplay.DataBind();
      }
  }
  </code></pre>