Ok, try:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Page.RouteData.Values["Id"] != null )
{
int id;
if (int.TryParse(Page.RouteData.Values["Id"].ToString(), out id) == true )
{
Adapter = new SqlDataAdapter("SELECT Subjects.SubjectId,Subjects.Title,AgePeriods.Period,Users.UserName From Subjects INNER JOIN AgePeriods ON Subjects.AgeId = AgePeriods.AgePeriodId INNER JOIN Users ON Subjects.UserId = Users.UserId WHERE CId = '" + id + "' ORDER BY Subjects.SubjectId DESC ", con);
Adapter.Fill(ds, "Subjects");
GridView1.DataSource = ds.Tables["Subjects"];
GridView1.DataBind();
Session["SubjectsData"] = ds.Tables["Subjects"];
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridView1.Rows[i].Cells[1].Visible = false;
GridView1.Rows[i].Cells[2].Visible = false;
}
}
else
{
Response.Redirect("homepage.aspx");
}
}
}
}
And then in the page index changing method:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = Session["SubjectsData"];
GridView1.DataBind();
}