Set all the properties associated with paging before the method is called Databind(). When you use Custom Paging, you will have to handle the event GridView1_PageIndexChanging. You need to modify the current PageIndex file and bind it GridViewas follows:
void bindGridview()
{
SqlCommand command = new SqlCommand("(SELECT ......", Connection);
SqlDataAdapter myAdapter = new SqlDataAdapter(command);
DataTable dt = new DataTable();
myAdapter.Fill(dt);
command.Connection = connection;
command.Connection.Open();
GridView1.AllowPaging = true;
GridView1.PageSize = 15;
GridView1.DataSource = dt;
GridView1.DataBind();
command.Connection.Close();
command.Connection.Dispose();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridview();
}
If you also bind the GridView to Page_Load, follow these steps:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
bindGridview();
}