c# - Asp .Net, sorting grid view error -


on click of email fiend in gridview, nothing happens. here code. please help. new asp .net.

i have set onsort = "gvdetails_sorting" , sorting =true

front end :

<asp:templatefield headertext="email id">     <itemtemplate>         <asp:label id="lblemailid" runat="server" text='<%# bind("email_id") %>'             wrap="true" width="100%" sortexpression="email_id">         </asp:label>                                              </itemtemplate> 

back end :

#region "properties" public sortdirection gridviewsortdirection {         {         if (viewstate["sortdirection"] == null)         {             viewstate["sortdirection"] = sortdirection.ascending;         }         return (sortdirection)viewstate["sortdirection"];     }     set { viewstate["sortdirection"] = value; } } #endregion     protected void page_load(object sender, eventargs e) {     if (!ispostback)     {         this.bindgrid();     }  }  protected void bindgrid() {      try     {     agent_supervisor_email obj = new agent_supervisor_email();     dataset ds = new dataset();     ds = obj.fillgrid();     gvdlist.datasource = ds;     gvdlist.databind();     }      catch (exception ex)      {          exceptionhandle(ex);      } }  private void sortgridview(string sortexpression, string direction) {     try     {         if ((viewstate["data"] != null))         {             dataview dv = new dataview();             dv = (dataview)viewstate["data"];             dv.sort = sortexpression + " " + direction;             gvdlist.datasource = dv;             gvdlist.databind();         }     }     catch (exception ex)     {         exceptionhandle(ex);     } } 

other code in between. following code.

 protected void gvdlist_sorting(object sender, gridviewsorteventargs e) {     try     {         string sortexpression = e.sortexpression;         if (gridviewsortdirection == sortdirection.ascending)         {             gridviewsortdirection = sortdirection.descending;             sortgridview(sortexpression, "desc");         }         else         {             gridviewsortdirection = sortdirection.ascending;             sortgridview(sortexpression, "asc");         }     }     catch (exception ex)     {         exceptionhandle(ex);     } } 

it not give me error. code seems nothing.

1) check setting gridview properties onsorting , allowsorting correctly:

onsorting="gvdlist_sorting" allowsorting="true" 

2) mentioned markus, check if viewstate["data"] contains data. haven't posted code sets viewstate["data"], perhaps not setting anywhere , sorting code not run.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -