The only way is to hide the Footer Row on all pages except the last page as shown below
Database
Northwind
HTML
<asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="false" AllowPaging="true"
PageSize="10" ShowFooter="true" OnPageIndexChanging="gvProducts_OnPageIndexChanging" OnDataBound = "OnDataBound">
<Columns>
<asp:TemplateField HeaderText="ProductName">
<ItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtProductName" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="QuantityPerUnit">
<ItemTemplate>
<asp:Label ID="lblQuantityPerUnit" runat="server" Text='<%# Eval("QuantityPerUnit") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtQuantityPerUnit" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UnitPrice">
<ItemTemplate>
<asp:Label ID="lblUnitPrice" runat="server" Text='<%# Eval("UnitPrice") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtUnitPrice" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UnitsInStock">
<ItemTemplate>
<asp:Label ID="lblUnitsInStock" runat="server" Text='<%# Eval("UnitsInStock") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtUnitsInStock" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
PopulateProducts();
}
}
protected void gvProducts_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.gvProducts.PageIndex = e.NewPageIndex;
this.PopulateProducts();
}
protected void OnDataBound(object sender, EventArgs e)
{
gvProducts.FooterRow.Visible = this.gvProducts.PageIndex == this.gvProducts.PageCount - 1;
}
private void PopulateProducts()
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT [ProductName],[QuantityPerUnit],[UnitPrice],[UnitsInStock] FROM [Products]", conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
this.gvProducts.DataSource = ds;
this.gvProducts.DataBind();
}
}
}
}