First of all,create one function that fills your GridView
protected void fillgrid()
{
SqlCommand cmd = new SqlCommand("select * from table", connection);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
connection.Close();
}
Call this function as follows:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillgrid();
}
}
And implement code as follows:
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
fillgrid();
}
Regards..