Posts

Showing posts from April, 2009

Sorting Ascending and Descending

Toggling the direction of your datagrid sort is easy using a session to remember which direction you sorted last.   You will want to declare an empty string in the top of your page       Dim SortField As String Then on your sort command add this logic - Example of entire command Private Sub dgTaskExceptions_SortCommand( ByVal source As Object , ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgTaskExceptions.SortCommand     SortField = e.SortExpression If Session( "toggle" ) = True Then SortField += " DESC" Session( "toggle" ) = False Else SortField += " Asc" Session( "toggle" ) = True End If Dim orderstring As String = SortField 'REBIND dgTaskExceptions.DataSource = POTracking_Data.tracking.getSampleTasks(orderstring) dgTaskExceptions.DataBind() End Sub   In my datalayer I add this logic to my query and pass in an OPTIONAL value Dim orderbyString As String = String .Empt