title: Putting GridView data in a DataTable
body: <p>I'm trying to save a <code>GridView</code> to a <code>DataTable</code>.</p>
  
  <p>I have code which should in theory do it but I keep getting this error:</p>
  
  <blockquote>
    <p>Column 0 doesn't exist</p>
  </blockquote>
  
  <p>Here is my code: </p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
      {
          DataTable dt = new DataTable();
          for (int j = 0; j &lt; GridView1.Rows.Count; j++)
          {
              DataRow dr;
              GridViewRow row = GridView1.Rows[j];
              dr = dt.NewRow();
              for (int i = 0; i &lt; row.Cells.Count; i++)
              {
                  dr[i] = row.Cells[i].Text;
              }
  
              dt.Rows.Add(dr);
          }
      }
  </code></pre>
  
  <p>Any help on how to fix this?</p>