You need to sign in to do that
Don't have an account?

Showing predefined custom fields data on visualforce page.
Hi All,
I have an objecte created with custom field Gender (type is pick list and contains 2 values Male and Female). Now I want to show this values on my visualforce page.
Can anyone please tell me how I can do that ?
When I searched on internet i got this piece of code :
For example suppose my object name is 'Information' and picklist custom field is 'Gender' How I can write this in above snippest.
Also after that I want to send selected value to apex controller.
Thanks in advance.
Best Regards,
Abhishek
I have an objecte created with custom field Gender (type is pick list and contains 2 values Male and Female). Now I want to show this values on my visualforce page.
Can anyone please tell me how I can do that ?
When I searched on internet i got this piece of code :
<apex:selectList value="{!countries}" multiselect="true"> <apex:selectOptions value="{!items}"/> </apex:selectList><p/>but I only know my object name and field name. Not sure how to use above.
For example suppose my object name is 'Information' and picklist custom field is 'Gender' How I can write this in above snippest.
Also after that I want to send selected value to apex controller.
Thanks in advance.
Best Regards,
Abhishek
Please use the following code:
Page:
**********
<apex:page controller="AjaxController">
<apex:form >
<apex:outputLabel >Gender</apex:outputLabel>
<apex:selectList size="1">
<apex:selectOptions value="{!lstGender}"></apex:selectOptions>
</apex:selectList>
</apex:form >
</apex:page>
Controller:
*******************
public class AjaxController {
public selectOption[] lstGender { get; set; }
public AjaxController(){
lstGender = new selectoption[]{};
Schema.describeFieldresult f1 = Account.Gender__c.getdescribe();//You can use any object in place of account
for(Schema.picklistEntry p1 :f1.getPicklistValues()){
lstGender.add(new selectOption(p1.getLabel(),p1.getLabel()));
}
}
This works for you. dont forget to mark it as solution.
Regards,
Vijay
All Answers
You can read more about Standard controllers here: https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_std.htm
If you're looking at anything custom, you need to consider a combination of standard controller and a custom extension controller.
Your Visualforce page may look like the following (not much different here other than the extensions attribute:
Your apex may look like the following:
For more info on extension controllers, see here: https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller.htm
Note, the above example will work for Picklist fields on an sobject, but if you need to create a custom select list like the one in the example you found, you're looking at something slightly more complex than the above example I posted.
Please use the following code:
Page:
**********
<apex:page controller="AjaxController">
<apex:form >
<apex:outputLabel >Gender</apex:outputLabel>
<apex:selectList size="1">
<apex:selectOptions value="{!lstGender}"></apex:selectOptions>
</apex:selectList>
</apex:form >
</apex:page>
Controller:
*******************
public class AjaxController {
public selectOption[] lstGender { get; set; }
public AjaxController(){
lstGender = new selectoption[]{};
Schema.describeFieldresult f1 = Account.Gender__c.getdescribe();//You can use any object in place of account
for(Schema.picklistEntry p1 :f1.getPicklistValues()){
lstGender.add(new selectOption(p1.getLabel(),p1.getLabel()));
}
}
This works for you. dont forget to mark it as solution.
Regards,
Vijay
Regards,
Abhishek