title: how to add a new row in gridview using C#?
body: <p>I want to retrieve a data from database, after modifying the record then I want to show it in Gridview.</p>
  
  <p>I already created column names through <code>Edit columns</code> those names are <code>Date,Location,Job Title,Details</code>.</p>
  
  <p>This is my asp.net code</p>
  
  <pre><code>&lt;asp:GridView ID="GridViewRecord" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None"&gt;
                  &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
                  &lt;Columns&gt;
                      &lt;asp:BoundField HeaderText="Date" /&gt;
                      &lt;asp:BoundField HeaderText="Location" /&gt;
                      &lt;asp:BoundField HeaderText="Job Title" /&gt;
                      &lt;asp:BoundField HeaderText="Experience" /&gt;
                      &lt;asp:HyperLinkField HeaderText="Details" /&gt;
                  &lt;/Columns&gt;
                  &lt;EditRowStyle BackColor="#999999" /&gt;
                  &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
                  &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
                  &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt;
                  &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt;
                  &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt;
                  &lt;SortedAscendingCellStyle BackColor="#E9E7E2" /&gt;
                  &lt;SortedAscendingHeaderStyle BackColor="#506C8C" /&gt;
                  &lt;SortedDescendingCellStyle BackColor="#FFFDF8" /&gt;
                  &lt;SortedDescendingHeaderStyle BackColor="#6F8DAE" /&gt;
              &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Then I try to add one sample record directly. But I am getting an error.
  This is my c# code on page load</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      if (!this.IsPostBack)
      {
          DataTable dt = new DataTable();
  
          DataRow dr = dt.NewRow();
          dr[0] = "12-12-12"; //Error message occured here
          dr[1] = "Jeddah";
          dr[2] = "Java";
          dr[3] = "2";
          dr[4] = "View Details";
  
          dt.Rows.Add(dr);
          GridViewRecord.DataSource = dt;
          GridViewRecord.DataBind();
      }
  }
  </code></pre>
  
  <p>Error message:</p>
  
  <blockquote>
    <p>An exception of type 'System.IndexOutOfRangeException' occurred in` System.Data.dll but was not handled in user code<br>
    Additional information: Cannot find column 0.</p>
  </blockquote>
  
  <p>I am new to c#, thanks</p>