Annoying postback and paging issue

angel

New Member
I asked a similar question to this but the circumstances have changed.I bind my gridview through code rather than on the source.The pagination works fine, but if I click a button on second page of the gridview (after pagination), the postback is causing the pagination to reset to page 1. Can anyone tell me what I'm doing wrong?Within my pageload i have set the !POSTBACK method as shown i.e if there is postback event, then it shouldn't reset the grid but it does!Heres the onload:\[code\] protected void Page_Load(object sender, EventArgs e) { if (Session["usersName"] != null) { object a = Session["_id"]; IDMaster = Convert.ToInt32(a); GridView1.Columns[10].Visible = true; GridView1.Columns[11].Visible = true; } else { GridView1.Columns[10].Visible = false; GridView1.Columns[11].Visible = false; } if (!IsPostBack) { BindGrid(); }\[/code\]The BindGrid();\[code\] SqlConnection sqlcon = new SqlConnection(connstring); SqlCommand sqlcmd = new SqlCommand("select * from Coffees ORDER BY coffeeName ASC", sqlcon); SqlDataAdapter adp = new SqlDataAdapter(sqlcmd); DataSet ds = new DataSet(); adp.Fill(ds); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind();\[/code\]Page index method:\[code\] protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; if(ViewState["searchTerm"] != null) { object a = ViewState["searchTerm"]; string reloadTerm = a.ToString(); setGrid(reloadTerm); }\[/code\]
 
Back
Top