dOOdad, Sorting in an ASP datagrid made easy

By patrickwellink
March 17, 2005

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
‘ it’s on the same column, reverse the sort
If OldSortOrder = NewSortOrderA Then
MyQuestions.Sort = NewSortOrderD
MyQuestions.Sort = NewSortOrderA
End If
   End If

   ‘Rewind the Questions

   ‘ Remove old instance from cache and add the Sorted one
   Cache.Insert(“MyQuestions”, MyQuestions)

   ‘Bind the Grid

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 !.

Comments: 1

  1. Patrick Wellink says:

    No invented it myself !!!!

    But i will have a look at the SBC templates

Comments are closed.

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta