Gridview inserting
<p>Hi friends. So far as my previous post for gridview inserting without datasource, databind, dataset, or datatable I have used this coding still i am getting an error:</p>

<h2>design.aspx:</h2>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Grid.aspx.cs" Inherits="Grid" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head id="Head1" runat="server"&gt;
  &lt;title&gt;Untitled Page&lt;/title&gt;
  &lt;style type="text/css"&gt;
    .style1
    {
      width: 97px;
    }
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;form id="form1" runat="server" autocomplete="on"&gt;
  &lt;div&gt;
    &lt;table style="width: 100%;"&gt;
      &lt;tr&gt;
        &lt;td class="style1"&gt;
          &lt;asp:Label ID="empname" runat="server" Text="Emp Name"&gt;&lt;/asp:Label&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;asp:TextBox ID="txtname" runat="server"&gt;&lt;/asp:TextBox&gt;
        &lt;/td&gt;
        &lt;td&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td class="style1"&gt;
          &lt;asp:Label ID="lblDesignation" runat="server" Text="Designation"&gt;&lt;/asp:Label&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;asp:TextBox ID="txtDesignation" runat="server"&gt;&lt;/asp:TextBox&gt;
        &lt;/td&gt;
        &lt;td&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td class="style1"&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;asp:Button ID="btnadd" runat="server" Text="Add" OnClick="btnadd_Click" Style="height: 26px" /&gt;
          &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
        &lt;/td&gt;
        &lt;td&gt;
          &amp;nbsp;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
    &lt;table style="width: 100%;"&gt;
      &lt;tr&gt;
        &lt;td&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;div&gt;
            &lt;asp:GridView ID="grvname" runat="server" AutoGenerateColumns="False"&gt;
              &lt;Columns&gt;
                &lt;asp:TemplateField HeaderText="Emp Name"&gt;&lt;/asp:TemplateField&gt;
                &lt;asp:TemplateField HeaderText="Designation"&gt;&lt;/asp:TemplateField&gt;
              &lt;/Columns&gt;
            &lt;/asp:GridView&gt;
          &lt;/div&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<h2>codebehind file:</h2>

<pre><code>using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Grid : System.Web.UI.Page
{

  protected void Page_Load(object sender, EventArgs e)
  {

  }

  protected void btnadd_Click(object sender, EventArgs e)
  {
    GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);

    //Add the two Columns    
    row.Cells.AddRange(CreateCells());

    //get a reference to the table that holds this row
    //Table tbl = (e.Row.Parent as Table);
    Table tbl = (grvname.Rows[grvname.Rows.Count + 1].Parent as Table);-------&gt;getting error here 

    //Add the row at the end of the list, but before the footer.
    tbl.Rows.AddAt(grvname.Rows.Count + 1, row);

    //Add the row at the end of the list, but before the footer.
    //tbl.Rows.AddAt(grvname.Rows.Count + 1, row);
  }

  private TableCell[] CreateCells()
  {
    TableCell[] cells = new TableCell[2];
    TableCell cell;
    Label lbl;


    //The order item column
    cell = new TableCell();
    lbl = new Label();
    lbl.Text = txtname.Text;
    cell.Controls.Add(lbl);
    cells[0] = cell;

    //The price column
    cell = new TableCell();
    lbl = new Label();
    lbl.Font.Bold = true;
    lbl.Text = txtDesignation.Text;
    cell.HorizontalAlign = HorizontalAlign.Right;
    cell.Controls.Add(lbl);
    cells[1] = cell;
    return cells;
  }
}
</code></pre>
