I am posting this on a well covered topic, because the examples I saw online were stupidly complex for this simple task. Now, I don’t mean to say that this is the most efficient method, but for smaller sets of data (we have less than 1000 records returned from this query) it is fast and easy.
Obviously, make sure you have the GridView set to allow paging. You will need to add an event handler for the GridViewPageIndexChanging (Not “Changed”). There is a private property for the class, ds which is a custom DataSet we have in our application. Any DataSet or DataTable (binding source?) will (should) work.
[code lang="c"]protected void gvUsers_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataTable dt = ds.GetUsers;
gvUsers.DataSource = dt;
gvUsers.PageIndex = e.NewPageIndex;
gvUsers .DataSource = dt;
gvUsers .DataBind();
}[/code]