dOOdad, Sorting in an ASP datagrid made easy

I have been playing around with the dOOdad architecture and  found out something very nice about this architecture.

Private Sub dgQuestions_SortCommand(Bla bla..) Handles dgQuestions.SortCommand

   ' Let's get the Questions from the cache
   MyQuestions = Cache.Get("MyQuestions")

   ' Determine some sort orders
   Dim OldSortOrder As String = MyQuestions.Sort
   Dim NewSortOrderD As String = e.SortExpression + " DESC"
   Dim NewSortOrderA As String = e.SortExpression + " ASC"

   ' See if the sort is on a new column
   If OldSortOrder <> NewSortOrderA And OldSortOrder <> NewSortOrderD Then
     
' Sort is on a new column
     
MyQuestions.Sort = NewSortOrderD
   Else
     
' it's on the same column, reverse the sort
     
If OldSortOrder = NewSortOrderA Then
        
MyQuestions.Sort = NewSortOrderD
     
Else
        
MyQuestions.Sort = NewSortOrderA
     
End If
   End If

   'Rewind the Questions
   MyQuestions.Rewind()

   ' Remove old instance from cache and add the Sorted one
   Cache.Remove("MyQuestions")
   Cache.Insert("MyQuestions", MyQuestions)

   'Bind the Grid
   BindGrid()

End Sub

The nice part about it is that this piece of code wil look the same for every datagrid. Only the BusinessClass will vary. And presto we have sorting on every column, Ascending and descending !.

Published 03-17-2005 10:03 AM by Patrick Wellink
Filed under: ,

Comments

# re: dOOdad, Sorting in an ASP datagrid made easy

Thursday, March 17, 2005 3:41 PM by Patrick Wellink
Good one :)

You caught this of of one of SBC's templates ?

# re: dOOdad, Sorting in an ASP datagrid made easy

Friday, March 18, 2005 7:03 AM by Patrick Wellink
No invented it myself !!!!

But i will have a look at the SBC templates