[SalesForce] Sorting functionality using dynamic soql

I have created a visual force page in Account page that displays related opportunities by RecordType(5 Records at a time) for the given Account and when click on Go to List it directs to new VF page with all the related list by Opportunity record type.
Now, I'm trying to implement Sorting Functionality in the new VF page that displays all the related list by Opportunity record type. I cannot implement using dynamic Soql. Is there a way to do it.

Here is my code
Controller:

public with sharing class OppListView {
Public static set<String> record_types_for_orders = new set<String>{
           'Order1', 
           'Order2'};
Public static set<String> record_types_for_mOpportunities = new set<String>{
           'US Opportuntiy',
           'UState Opportunity'};  

private transient List<RecordType> recordTypeNames = new List<RecordType>();
private transient set<Id> orderRecordTypeIDs = new set<Id>();
private transient set<Id> oppRecordTypeIDs = new set<Id>();

private list<Opportunity> theOrders = new list<Opportunity>();
private list<Opportunity> theOpps = new list<Opportunity>();    

public Account acct{get;set;}
public string redirectUrl {public get;private set;}

List<aOLIPlus> scheduleArray;
List<aOLIPlus1> scheduleArray1;


public String selectedVal{get;set;}
 public String checkedVal{get {if(checkedVal ==null){checkedVal='DESC';}return checkedVal;}
    set;
}
public String sortField {get { if (sortField == null) {sortField = 'CloseDate'; } return sortField; }
set;
}

public OppListView(ApexPages.StandardController ctrl){
   acct = new Account();
   //get account Id from Url  
   acct.Id = System.currentPageReference().getParameters().get('id');

    recordTypeNames = [Select Id, Name, sObjectType From RecordType Where sObjectType = 'Opportunity']; 

    for(RecordType rt : recordTypeNames){  
        if(record_types_for_orders.contains(rt.Name)){
            orderRecordTypeIDs.add(rt.Id);
        } else if(record_types_for_Opportunities.contains(rt.Name)){
            oppRecordTypeIDs.add(rt.Id);
        }   
    }

   theOrders = [Select Name, StageName, Amount, CloseDate, Agency__c, RecordTypeId, RecordType.Name
                 From Opportunity Where AccountId = :acct.Id And RecordTypeId IN :orderRecordTypeIDs 
             Order By CloseDate DESC];


    theOpps = [Select Name, StageName, Amount, CloseDate, Agency__c, RecordTypeId, RecordType.Name
                 From Opportunity Where AccountId = :acct.Id And RecordTypeId IN :oppRecordTypeIDs
             Order By CloseDate DESC ];


    theMOpps = [Select Name, StageName, Amount, CloseDate, Agency__c, RecordTypeId, RecordType.Name
                 From Opportunity Where AccountId = :acct.Id And RecordTypeId IN :moppRecordTypeIDs
             Order By CloseDate DESC]; 

scheduleArray = new List<aOLIPLus>();
    for(Opportunity thisMaster : theOrders)        
        scheduleArray.add(new aOLIPlus(thisMaster, thisMaster.Name,thisMaster.StageName, thisMaster.Amount, thisMaster.CloseDate, thisMaster.Agency__c,thisMaster.RecordTypeId,thisMaster.RecordType.Name));        

    scheduleArray1 = new List<aOLIPLus1>();
    for(Opportunity thisMaster1 : theOpps)        
        scheduleArray1.add(new aOLIPlus1(thisMaster1, thisMaster1.Name,thisMaster1.StageName, thisMaster1.Amount, thisMaster1.CloseDate, thisMaster1.Agency__c,thisMaster1.RecordTypeId,thisMaster1.RecordType.Name));      

}
public List<aOLIPlus> getScheduleArray()
{    
    return scheduleArray;
}
public List<aOLIPlus1> getScheduleArray1()
{    
    return scheduleArray1;
}  

public PageReference gotoAcct()
{            
    String str = 'https://cs8.salesforce.com/'+ acct.id;
    PageReference newPage = new PageReference(str);
    newPage.setRedirect(false);
    return newPage;
}

//Using Seperate Wrapper classes get records from all categories
 public class aOLIPlus
{    
    public Opportunity iOLI {get; set;}
    public String iName{get;set;}
    public String iStageName {get; set;}
    public String iAmount {get;set;}
    public Date iCloseDate{get;set;}
    public String iAgency {get; set;}
    public String iRecordType {get; set;}
    public Boolean selected {get; set;}       

    public aOLIPlus(Opportunity aa,String aName, String aStageName, Decimal aAmount, Date aCloseDate,String aAgency,String aRecordTypeId,String aRecordType)
    {
      iOLI = aa;
      iName = aName;  
      iStageName = aStageName;
      iAmount = aAmount;
      iCloseDate = aCloseDate; 
      iAgency = aAgency;  
      iRecordType = aRecordType;
      selected = false;
    }    
}
public class aOLIPlus1
{    
    public Opportunity iOLI {get; set;}
    public String iName{get;set;}
    public String iStageName {get; set;}
    public String iAmount {get;set;}
    public Date iCloseDate{get;set;}
    public String iAgency {get; set;}
    public String iRecordType {get; set;}
    public Boolean selected {get; set;}       

    public aOLIPlus1(Opportunity aa, String aName, String aStageName, Decimal aAmount, Date aCloseDate,String aAgency,String aRecordTypeId,String aRecordType)
    {
      iOLI = aa;
      iName = aName;  
      iStageName = aStageName;
      iAmount = aAmount;
      iCloseDate = aCloseDate; 
      iAgency = aAgency;  
      iRecordType = aRecordType;
      selected = false;
    }    
}
public PageReference search(){
    //if(sortField =='')
    PageReference pageRef = new PageReference('/apex/OppSortView?id='+ acct.Id+'?sortField='+sortField+'?checkedVal='+checkedVal);
    //else if(sortfield == '')    
    pageRef.setRedirect(true);
    return pageRef;

}
}

Visual Force Page:

<apex:page standardController="Account" extensions="OppListView">
<apex:form >
<apex:sectionheader title="Orders for {!account.Name}"/> 
<apex:pageBlock >
     <div align='center'>
        <apex:commandButton action="{!gotoAcct}" value="Back to Account"/>
           </div>  
     <div align='right'>
           <apex:outputLabel value="Sort by" for="sortField">
            <apex:selectList value="{!sortField}" size="1">
                <!--apex:actionSupport event="onchange" action="{!search}"/!-->
                <apex:selectOption itemLabel="Close Date" itemValue="CloseDate"/>
                <apex:selectOption itemLabel="Opportunity Name" itemValue="OpportunityName"/>    
                <apex:selectOption itemLabel="Stage" itemValue="Stage"/>    
                <apex:selectOption itemLabel="Amount" itemValue="Amount"/> 
                <apex:selectOption itemLabel="Agency" itemValue="Agency"/> 
             </apex:selectList>
              </apex:outputLabel>
          <apex:commandButton action="{!search}" value="View"/>

         <apex:selectRadio value="{!checkedVal}">
            <!--apex:actionSupport event="onchange" action="{!search}"/!-->
                <apex:selectOption itemLabel="Ascending" itemValue="Ascending"/>
                <apex:selectOption itemLabel="Descending" itemValue="Descending"/>  
        </apex:selectRadio>
      </div> 
    <div style="overflow: scroll; height: 700px;" >  
     <apex:pageBlocktable value="{!scheduleArray}" var="e" columnsWidth="25%,15%,15%,15%30%">
     <apex:column >
    <apex:outputlink value="https://cs8.salesforce.com/{!e.iOLI.Id}" target="_top">{!e.iName}</apex:outputlink>
    <!-- apex:outputText value="{!e.iName}" /!-->
    </apex:column>
    <apex:column > <apex:outputText value="{!e.iStageName}" /></apex:column>
    <apex:column ><apex:outputText value="{!e.iAmount}" /></apex:column>
    <apex:column ><!--apex:outputText value="{!e.iCloseDate}" /!-->
        <apex:outputText value="{0, date, M/d/y }"><apex:param value="{!e.iCloseDate}"/>
            </apex:outputText></apex:column>
    <apex:column ><apex:outputText value="{!e.iAgency}" /></apex:column>
    <apex:column ><apex:outputText value="{!e.iRecordType}" /></apex:column>

</apex:pageBlocktable>   
         </div>
</apex:pageBlock>
</apex:form>
</apex:page>

Best Answer

Have a look at a blog done by Jeff Douglas:

http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/

@naga42 is right in terms of building the SOQL query with the additional search parameters. You do not appear to be utilizing any of the sort parameters that are passed into your controller. The attached post should give you the framework to accomplish what you are after.