c# - Gridview filter resetting on paging -


i have gridview i'm binding database within onload method.

as shown:

      if (!ispostback)         {            sqlconnection sqlcon = new sqlconnection(connstring);            sqlcommand sqlcmd = new sqlcommand("select * coffees order coffeename asc", sqlcon);            sqldataadapter adp = new sqldataadapter(sqlcmd);            dataset ds = new dataset();            adp.fill(ds);            gridview1.datasource = ds.tables[0];            gridview1.databind();          } 

i'm allowing users filter gridview on search term. issue i'm following @ moment when change pages, filter lost.

i have read need rebind filter eachtime , im getting stuck.

here filter:

        private void setgrid(string searchterm)     {         if (ispostback)         {             string item = dropdownlist2.selectedvalue;             sqlconnection sqlcon = new sqlconnection(connstring);             sqlcommand sqlcmdd = new sqlcommand("select * coffees " + searchterm + " = '" + item + "'", sqlcon);             sqldataadapter adpp = new sqldataadapter(sqlcmdd);             dataset dss = new dataset();             adpp.fill(dss);             gridview1.datasource = dss.tables[0];             gridview1.databind();          }      } 

as shown above have if statement handles postback. postback still have try , head around believe doing reloading grid if postback. have tried change if postback not affected ignores filter together.

hopefully can give me idea i'm going wrong. , how can apply filter acrodd of y pages.

i saved search term viewstate variable, applied in page index changing method if check if null or not. either re-bound grid on searchterm, or standard bind show results.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -