Object reference not set to an instance of an object
<p>i am stuck with this error since last few hours.. i dont know what am i doing wrong here.. </p>

<pre><code>    &lt;script type="text/javascript"&gt;
    function viewProfile(index)
    {
        var GridID = document.getElementById("PersonGridView");
        var row=GridID.rows[parseInt(index)+1];
        window.open('detailsid.aspx?'+row);
    }
    &lt;/script&gt;
</code></pre>

<p>
    
    
        
            </p>

<pre><code>        &lt;Columns&gt;
            &lt;asp:BoundField HeaderText="First Name" DataField="FirstName" /&gt;
            &lt;asp:BoundField HeaderText="Last Name" DataField = "LastName" /&gt;
            &lt;asp:BoundField HeaderText="HomePhoneNumber" DataField="HomePhoneNumber" /&gt;
            &lt;asp:TemplateField HeaderText="ViewDetails"&gt;
            &lt;ItemTemplate&gt;
            &lt;asp:Button ID="Deatils" runat="server" Text="Details" /&gt;
            &lt;/ItemTemplate&gt;    

            &lt;/asp:TemplateField&gt;

            &lt;asp:TemplateField HeaderText="Actions"&gt;
            &lt;ItemTemplate&gt;
            &lt;asp:Button ID="Modify" runat="server" Text="Modify" /&gt;
            &lt;asp:Button ID="Delete" runat="server" Text="Delete" /&gt;

            &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;


        &lt;/Columns&gt;


        &lt;FooterStyle BackColor="#CCCC99" /&gt;
        &lt;PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /&gt;
        &lt;SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /&gt;
        &lt;HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /&gt;
        &lt;AlternatingRowStyle BackColor="White" /&gt;
    &lt;/asp:GridView&gt;
&lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p></p>

<pre><code>&lt;p&gt; Code Behind : 
protected void PersonGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {

               if (e.Row.RowType == DataControlRowType.DataRow)
            {
         var ID = PersonGridView.DataKeys[e.Row.RowIndex]["ID"].ToString();

                Button btnDetails = (Button)FindControl("Details");
                Button btnModify = (Button)FindControl("Modify");
                Button btnDelete = (Button)FindControl("Delete");
                btnModify.CommandName = "Modify";
                btnDelete.CommandName = "Delete";
                btnDetails.CommandName = "Details";
                btnDelete.CommandArgument = btnModify.CommandArgument = string.Format("{0}", ID);
                btnDetails.Attributes["onclick"] = string.Format("viewProfile({0}); return false;", ID);


            }
        }
</code></pre>
