Payowlynoneyh
New Member
I have a gridview that I'm binding from my database within my onload method.As shown:\[code\] if (!IsPostBack) { 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\]I'm allowing my users to filter the gridview on their search term. The issue I'm following at the moment is that when i change pages, the filter is lost.I have read I need to rebind the filter eachtime and this is where im getting stuck.Here is my filter:\[code\] private void setGrid(string searchTerm) { if (IsPostBack) { string item = DropDownList2.SelectedValue; SqlConnection sqlcon = new SqlConnection(connstring); SqlCommand sqlcmdd = new SqlCommand("SELECT * FROM Coffees WHERE " + searchTerm + " = '" + item + "'", sqlcon); SqlDataAdapter adpp = new SqlDataAdapter(sqlcmdd); DataSet dss = new DataSet(); adpp.Fill(dss); GridView1.DataSource = dss.Tables[0]; GridView1.DataBind(); } }\[/code\]As shown above I have an if statement that handles the Postback. Postback is something I still have to try and get my head around but I believe what this is doing is reloading the grid if its a Postback. I have tried to change this so if it is a Postback it is not affected but this just ignores the filter all together.Hopefully someone can give me an idea where I'm going wrong. And How I can apply the filter acrodd all of y pages.