Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is whenever you call the GetData() function, your code is changing the dataview's sort property even if it's being called by PageIndexChaging event.</p> <pre><code>If (GridViewSortDirection = SortDirection.Ascending) Then GridViewSortDirection = SortDirection.Descending dv.Sort = CType(ViewState("sortExp") &amp; DESCENDING, String) Else GridViewSortDirection = SortDirection.Ascending dv.Sort = CType(ViewState("sortExp") &amp; ASCENDING, String) End If </code></pre> <p>You can modify your GetData() function to accept a SortDirection. Then, in your tblAdministrators_PageIndexChanging and tblAdministrators_Sorting events, just pass the GridViewSortDirection. Something like this:</p> <pre><code>Private Function GetData(sort As SortDirection) As Data.DataView ' your code here... End Function Protected Sub tblAdministrators_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles tblAdministrators.PageIndexChanging tblAdministrators.PageIndex = e.NewPageIndex tblAdministrators.DataSource = GetData(GridViewSortDirection) tblAdministrators.DataBind() End Sub Protected Sub tblAdministrators_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles tblAdministrators.Sorting ViewState("sortExp") = e.SortExpression GridViewSortDirection = If(GridViewSortDirection = SortDirection.Descending, SortDirection.Ascending, SortDirection.Descending) tblAdministrators.DataSource = GetData(GridViewSortDirection) tblAdministrators.DataBind() End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload