You need to sign in to do that
Don't have an account?
Krishna12
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;
}
}
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;
}
}
Glyn Anderson
Sr Developer | System Analyst | ClosedWon | closedwon.com
Certified Developer | Certified Advanced Administrator
Twitter: @GlynAtClosedWon
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>
If this solved the problem, please mark it as the "answer". This will mark the post as "solved". Thanks!
-Glyn