function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hari nadh babu EluruHari nadh babu Eluru 

Min Age and Max Age result can be show in another page

if user enter min age, max age . fetch all the students in btwn that min and max age

in above example try to load students in ascending order based on age

result can be shown in another page when clicked search button
Suraj Tripathi 47Suraj Tripathi 47
Hi Hari,

Please try this code:

vf Page 1:

<apex:page Controller="yaQuestionStudentMinMaxAge" >    
<apex:form >        
<apex:pageBlock title="Student Age">            
<apex:pageBlockSection columns="1">                
Min Age<apex:inputText value="{!minage}"/>                
Max Age<apex:inputText value="{!maxage}"/>                  
<apex:pageBlockButtons >                
<apex:commandButton action="{!search}" value="Search"/>            

Vf page 2:
<apex:page controller="yaQuestionStudentMinMaxAge" action="{!search1}">
     <apex:form >
        <apex:pageBlock title="Student Age">
             <apex:pageBlockTable value="{!studentObj}" var="c">
                <apex:column value="{!c.Name}"/>
                <apex:column value="{!c.minAge__c}"/>
                <apex:column value="{!c.maxAge__c}"/>            

Apex class:

public class yaQuestionStudentMinMaxAge {    
public string maxage{get;set;}    
public string minage{get;set;}    
public List <Student__c> studentObj {get;set;}            
public PageReference search() {        
PageReference redirectPage = new PageReference('');  //please put here your second vf page URL     
// system.debug('pageReference::'+redirectPage);                
redirectPage.getParameters().put('maximumage',maxage);             r
return redirectPage;    

public void search1(){          
integer minval = integer.valueof(ApexPages.currentPage().getParameters().get('minimumage'));        
 integer maxval = integer.valueof(ApexPages.currentPage().getParameters().get('maximumage'));        
studentObj = new list<Student__c>();        
studentObj=[select Name, minAge__c,maxAge__c from Student__c where minAge__c>=:minval AND maxAge__c<=:maxval ORDER  BY minAge__c ASC];
// you can sort the data in ascending order by minAge__c or maxAge__c.        

Hope this will help you.