Index was out of range. Must be non-negative and less than the size of the collection
<p>i am getting this error while tracking my datakey.. i am not sure why my datakey index is coming out of range.. here is my code :</p>

<pre><code>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            var dataKeys = GridView1.DataKeys[e.Row.RowIndex];
            dataKeys.Value.ToString();
            Label1.Text = "The key field value for the displayed record is " + dataKeys.Value.ToString();
        }
</code></pre>

<p>Header Part Of the GridView:

        
        
            
            
            
            
            
            
            
            
            
                
                
                </p>

<pre><code>        &lt;/ItemTemplate&gt;

        &lt;/asp:TemplateField&gt;
    &lt;/Columns&gt;
    &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" 
         /&gt;
    &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt;
    &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt;
    &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
    &lt;EditRowStyle BackColor="#999999" /&gt;
    &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
&lt;/asp:GridView&gt;

&lt;script language="javascript" type="text/javascript"&gt;
    function viewProfile(selectedRowIndex, firstName) {
        //alert(firstName);
        //var customGridView = document.getElementById('&lt;%= CustomGridView.ClientID %&gt;');
        var customGridView = document.getElementById('GridView1');
        if (customGridView) {
            var row = customGridView.rows[parseInt(selectedRowIndex) + 1];
            //var cell = customGridView.rows[parseInt(selectedRowIndex) +   1].cells[0];
            //            alert(row.cells[0].innerHTML);
            //            alert(row.cells[1].innerHTML);
            //            alert(row.cells[2].innerHTML);
            //            alert(row.cells[3].innerHTML);
            //            alert(row.cells[4].innerHTML);
            window.open('detatil.aspx?coaid=' + row.cells[1].innerHTML + '&amp;fnomia=' + row.cells[2].innerHTML, "", "scrollbars=no,height=300,width=300");
        }
    }
&lt;/script&gt;
</code></pre>

<p>The error is:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index</p>
