GridView.Rows.Count is always equal to GridView.PageSize - 4 on last page
<p>In the last page of GridView gv, in the RowCommand event of "Select" row event, gv.Rows.Count is always equal to gv.PageSize - 4, no matter how many rows are actually there in the gridview in the last page or whatever is the PageSize.</p>

<pre><code>&lt;asp:GridView ID="gvDocumentListGrid" runat="server" 
      AutoGenerateColumns="False" DataSourceID="odsDocumentList"
      AllowSorting="True" AllowPaging="True" PageSize="10" AutoGenerateSelectButton="True" 
      onrowcommand="gvDocumentListGrid_RowCommand" CssClass="gridSapphire" 
      PagerStyle-CssClass="pagerSapphire" 
      AlternatingRowStyle-CssClass="alterSapphire"
      onpageindexchanged="gvDocumentListGrid_PageIndexChanged" 
      Width="100%" EmptyDataText="List is empty." DataKeyNames="Id" 
      EnableViewState="true" onrowdatabound="gvDocumentListGrid_RowDataBound"&gt;

protected void gvDocumentListGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
    switch (e.CommandName)
    {
        case "Select":
            if (GetSelectedRow(e) != null)
                        // other code
            break;
    }
}


private GridViewRow GetSelectedRow(GridViewCommandEventArgs e)
{
    if (int.Parse(e.CommandArgument.ToString()) &gt; (gvDocumentListGrid.Rows.Count - 1))
        return null;

    return gvDocumentListGrid.Rows[int.Parse(e.CommandArgument.ToString())];
}
</code></pre>
