+ Start a Discussion
Hari nadh babu Eluru 7Hari nadh babu Eluru 7 

picklist select option

take a picklist which is having options male,female,others. if user select male and click button then show male students only in vf page
 
<apex:page controller="ChooseGender">
<apex:form >
    <apex:selectList id="ChooseGender" value="{!CG}" size="1">
            <apex:selectOption itemValue="Male" itemLabel="Male"/>
            <apex:selectOption itemValue="Female" itemLabel="Female"/>
            <apex:selectOption itemValue="Others" itemLabel="Others"/>
        </apex:selectList> 
<apex:commandButton value="Click me" action="{!PSO}"/>
</apex:form>
</apex:page>

 
Best Answer chosen by Hari nadh babu Eluru 7
Suraj Tripathi 47Suraj Tripathi 47
Hi Hari,

Pleare try this Here is the code:

VF PAge:
<apex:page controller="ChooseGender">
<apex:form >
    <apex:pageBlock>
    <apex:selectList id="ChooseGender" value="{!CG}" size="1">
            <apex:selectOption itemValue="Male" itemLabel="Male"/>
            <apex:selectOption itemValue="Female" itemLabel="Female"/>
            <apex:selectOption itemValue="Others" itemLabel="Others"/>
        </apex:selectList> 
<apex:commandButton value="Click me" action="{!PSO}"/>
    
    <apex:pageBlockTable value="{!stu}" var="c">
                <apex:column value="{!c.Name}"/>
                <apex:column value="{!c.Gender__c}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
</apex:form>
</apex:page>

Apex Class:
public class ChooseGender {
    public string CG {set;get;}
    
    public list<Student__c> stu {set;get;}   
    public void PSO(){
        stu = new  List<Student__c>();
        stu = [select Id, Name, Gender__c from Student__c where Gender__c =:CG];
        system.debug('stuList ::'+stu);
    }
}

Hope this will help you.
Thanks