title: Remove Empty row in gridview which is added automatically at the bottom of gridview
body: <p>I am using grid view to show records from database. Gridview has pagination and <code>pagesize</code> is set as <code>15</code>. And one column has link field when user click this link it proceed some functionality. Now what is my problem is </p>
  
  <ul>
  <li><p>1) when number of records less than page size the last page is
  shrunk. it's k for me. but on clicking view link in grid view the
  empty row added automatically. how do i remove these empty row?</p></li>
  <li><p>2) on clicking view link the page index changed to 1. example i am in
  3 page of grid view and clicking view link in 3rd page the page index
  number changed to 1 but the page shows 3rd row record. how do i fix
  this..?</p></li>
  </ul>
  
  <p>please any can help me.. thanks in advance</p>
  
  <p>grid view code:-</p>
  
  <pre><code>&lt;asp:GridView ID="gvGRNListAll" runat="server" AutoGenerateColumns="False" Style="width: 100%;"
      AllowPaging="True" PageSize="15" OnPageIndexChanging="gvGRNListAll_PageIndexChanging"
      CellPadding="4" ForeColor="#333333" BorderColor="#CCCCCC" ShowHeaderWhenEmpty="True"
      GridLines="None"&gt;
      &lt;AlternatingRowStyle BackColor="White" /&gt;
      &lt;PagerStyle CssClass="pager" /&gt;
      &lt;Columns&gt;
          &lt;asp:TemplateField HeaderText="S.No"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label1" runat="server" Text='&lt;%#Container.DataItemIndex+1 %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;ItemStyle HorizontalAlign="Left" Width="10%" /&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:BoundField DataField="LocationName" HeaderText="Location" /&gt;
          &lt;asp:BoundField DataField="SupplierName" HeaderText="Supplier Name" /&gt;
          &lt;asp:BoundField DataField="GRNNo" HeaderText="GRN No" /&gt;
          &lt;asp:BoundField DataField="InvoiceNo" HeaderText="In.No"&gt;
              &lt;ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="GRNDate" HeaderText="GRNDate" /&gt;
          &lt;asp:TemplateField HeaderText="Action" SortExpression="ExId" ControlStyle-ForeColor="Blue"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:HiddenField ID="hdnStoreCode" runat="server" Value='&lt;%# Eval("StoreCode") %&gt;' /&gt;
                  &lt;asp:HiddenField ID="hdnGRNNo" runat="server" Value='&lt;%# Eval("GRNNo") %&gt;' /&gt;
                  &lt;asp:LinkButton ID="lbView" OnClick="lbView_Click" runat="server" Text="View"&gt;&lt;/asp:LinkButton&gt;
              &lt;/ItemTemplate&gt;
              &lt;ControlStyle ForeColor="#FF3300" /&gt;
              &lt;HeaderStyle CssClass="GridHeaderROW" Width="10%" /&gt;
              &lt;ItemStyle CssClass="GridItemROW" Width="10%" /&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
      &lt;EmptyDataRowStyle HorizontalAlign="Center" VerticalAlign="Bottom" ForeColor="#FF3300" /&gt;
      &lt;EmptyDataTemplate&gt;
          No Records Found.
      &lt;/EmptyDataTemplate&gt;
      &lt;EditRowStyle BackColor="#2461BF" /&gt;
      &lt;FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
      &lt;HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" /&gt;
      &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /&gt;
      &lt;RowStyle BackColor="#EFF3FB" /&gt;
      &lt;SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /&gt;
      &lt;SortedAscendingCellStyle BackColor="#F5F7FB" /&gt;
      &lt;SortedAscendingHeaderStyle BackColor="#6D95E1" /&gt;
      &lt;SortedDescendingCellStyle BackColor="#E9EBEF" /&gt;
      &lt;SortedDescendingHeaderStyle BackColor="#4870BE" /&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>On <code>PageIndexChanged</code></p>
  
  <pre><code>protected void gvGRNListAll_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
      gvGRNListAll.PageIndex = e.NewPageIndex;
      SearchData();
      gvGRNListAll.PageIndex = 0;
  }
  </code></pre>
  
  <p>Searchdata Code :</p>
  
  <pre><code>public void SearchData()
      {
         DataTable dtGRN = objBAL.FilterGRNScannedList("filterGRNScannedList", suppliercode, grnno, locationcode, Fromdate, Todate, "");
         gvGRNListAll.DataSource = dtGRN; 
         gvGRNListAll.DataBind();
      }
  </code></pre>
  
  <p>Onclick event Code :</p>
  
  <pre><code>if (sender is LinkButton)
          {
              GridViewRow gvrCurrent = ((LinkButton)sender).NamingContainer as GridViewRow;
              hdnGRNNo = (HiddenField)gvrCurrent.FindControl("hdnGRNNo");
              hdnStore = (HiddenField)gvrCurrent.FindControl("hdnStoreCode");
              gvGRNListAll.Rows[gvrCurrent.RowIndex].BackColor = System.Drawing.Color.Empty;
              gvGRNListAll.Rows[gvrCurrent.RowIndex].BackColor = System.Drawing.ColorTranslator.FromHtml("#D8D8D8");
              if (hdnGRNNo != null &amp;&amp; hdnStore != null)
              {
                  GetGRNListForNo(hdnGRNNo.Value, Convert.ToInt32(hdnStore.Value));
              }
          }
  </code></pre>