c# - Problems with Session for Sorting my GridView -


i have problems session["tasktable"] datasource gridview. when open .aspx site first time session["tasktable"] null, if reload page (f5) session["tasktable"] datatable tasktable. how be? i'm able sort if first reload page. ideas? thanks

protected void page_load(object sender, eventargs e)     {          if (!page.ispostback)         {             datatable tasktable = new datatable("tasklist");             tasktable = dtcloned;                             session["tasktable"] = tasktable;             gv_projekte.datasource = session["tasktable"];             gv_projekte.databind();           }      } 

and sorting of gridview

protected void gv_sorting(object sender, gridviewsorteventargs e)     {         datatable dt = session["tasktable"] datatable;          if (dt != null)         {             //sort data.             dt.defaultview.sort = e.sortexpression + " " + getsortdirection(e.sortexpression);             gv_projekte.datasource = session["tasktable"];             gv_projekte.databind();         }     }      private string getsortdirection(string column)     {         // default, set sort direction ascending.         string sortdirection = "asc";          // retrieve last column sorted.         string sortexpression = viewstate["sortexpression"] string;          if (sortexpression != null)         {             // check if same column being sorted.             // otherwise, default value can returned.             if (sortexpression == column)             {                 string lastdirection = viewstate["sortdirection"] string;                 if ((lastdirection != null) && (lastdirection == "asc"))                 {                     sortdirection = "desc";                 }             }         }          // save new values in viewstate.         viewstate["sortdirection"] = sortdirection;         viewstate["sortexpression"] = column;          return sortdirection;     } 

that because of page.ispostback condition when page not postback assigned session variable value there untill session expire whatever session time out there.

take following exercise.

 protected void page_load(object sender, eventargs e)     {         if (session["a"]==null)         {             response.write("session empty");         }         else         {             response.write("session not empty");             response.write(session["a"].tostring());         }         if (!page.ispostback)         {             session["a"] = "jalpesh";         }     } 

here in blank page i'm doing same thing doing first time page load @ time print 'session empty' after session not empty till session expires print 'session not empty'.

so if need session value null have assign session null somewhere.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -