You need to sign in to do that
Don't have an account?
Sudhakar Reddy
How to retrieve the picklist value
Hi All,
Let us assume that I had one picklist. I had written one method in controller to populate picklist values.
After poulating values and after submitting page,if I want to retrieve the user selected value from that picklist,how can i do it?
Please help me out.
create a picklist field on Account, API name: Subcategories__c
Apex
public with sharing class VF_Picklist_Ctrl {
private final Account account;
public VF_Picklist_Ctrl() {
account = [SELECT Id, Name, Subcategories__c FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Account getAccount() {
return account;
}
public PageReference save() {
System.debug(' ------ User Selection: ' + account.Subcategories__c );
update account;
return null;
}
}
VF page:
<apex:page controller="VF_Picklist_Ctrl">
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Dependent Picklists" columns="2">
<apex:inputField value="{!account.Subcategories__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
test in browser like:
/apex/VF_Picklist1?id=AccountID
Hi Sudhakar
Jai Hu has answered your question if you have a picklist field on a object. But if you have a visual force page and custom controller on which you want to display a drop-down field with some values and want to get back selected value in controller please refer following code:
Here is controller:
Let me know if this doesn't solve the problem.
Thanks a lot.
But here i had one doubt.
Here what is the picklist field name in this example?
Are you binding your SelectList with a picklist field from a object?