I think an easy solution is to just use url parameters and session variables to keep track of the sort and then add an ORDER BY clause to the end of your SQL statement that will allow you to pass in the column and direction from the set session values.