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
Krishna12Krishna12 

gender count

Hi,

 I have one student object from that i am displaying values in visualforce page but i want to display number of males and females in that visualforce page i am not getting count of gender i am using picklist for gender, At the end of vf page i want to display male=10, female =10 for this may i know what i have to do.

My Vf Page


<apex:page controller="stu">
<apex:form>
  <apex:pageblock >
<apex:pageblockTable value="{!stulist}" var="s">
        <apex:column value="{!s.Student_Name__c}"/>
        <apex:column value="{!s.Contact_No__c}"/>
        <apex:column value="{!s.Gender__c}"/>
      </apex:pageblockTable>
    </apex:pageblock>
  </apex:form>
</apex:page>

public class stu
{
    Public List<Students__c> stulist = new List<Students__c>();
    public list<Students__c> getstulist(){
      stulist = [ select Student_Name__c, Contact_No__c,Gender__c  from Students__c];
     
       return stulist;
   
    }  
   
}
GlynAGlynA
In the post, I've given some code that will count the males and females and display those totals in the page.  Note that the query is now in the controller's constructor.

Glyn Anderson
Sr Developer | System Analyst | ClosedWon | closedwon.com
Certified Developer | Certified Advanced Administrator
Twitter: @GlynAtClosedWon
GlynAGlynA
<pre>
public class stu
{
    public List<Students__c> stulist { get; set; }
    public Integer numMales { get; set; }
    public Integer numFemales { get; set; }

    public stu()
    {
        stulist = [ select Student_Name__c, Contact_No__c,Gender__c  from Students__c];
        numMales = 0;
        numFemales = 0;
        for ( Students__c student : stulist )
        {
            if ( student.Gender__c == 'Male' ) numMales++;
            if ( student.Gender__c == 'Female' ) numFemales++;
        }
    }
}


<apex:page controller="stu">
<apex:form>
    <apex:pageblock >
        <apex:pageblockTable value="{!stulist}" var="s">
            <apex:column value="{!s.Student_Name__c}"/>
            <apex:column value="{!s.Contact_No__c}"/>
            <apex:column value="{!s.Gender__c}"/>
        </apex:pageblockTable>
        <apex:panelGrid columns="4">
            <apex:outputText value="Number of Males:"/>
            <apex:outputText value="{!numMales}"
            <apex:outputText value="Number of Females:"/>
            <apex:outputText value="{!numFemales}"
        </apex:panelGrid>
    </apex:pageblock>
</apex:form>
</apex:page>
</pre>
GlynAGlynA
Did this solve the problem?  Or do you need more help?

If this solved the problem, please mark it as the "answer".  This will mark the post as "solved".  Thanks!

-Glyn