void CustomersGridView_DataBound(Object sender, EventArgs e)
{
if (!IsPostBack)
{
// Call a helper method to display the current page number
// when the page is first loaded.
DisplayCurrentPage();
}
}
void CustomersGridView_PageIndexChanged(Object sender, EventArgs e)
{
// Call a helper method to display the current page number
// when the user navigates to a different page.
DisplayCurrentPage();
}
void DisplayCurrentPage()
{
// Calculate the current page number.
int currentPage = CustomersGridView.PageIndex + 1;
// Display the current page number.
Message.Text = "Page " + currentPage.ToString() + " of " +
CustomersGridView.PageCount.ToString() + ".";
}
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>