Type 5:Usage of Dynamic picklist in vf & Apex


<apex:page controller="dynamicpickone" sidebar="false" showHeader="false">

<apex:form >
 <apex:selectList id="selectpick" size="1" value="{!selectedValue}">
 <apex:selectOptions value="{!pickOptions}"/>
 <apex:actionSupport event="onchange" reRender="one"/>
 </apex:selectList>

<apex:outputPanel id="one">Selected Value is:
 <apex:outputText value="{!selectedValue}" />
 </apex:outputPanel>
 </apex:form>
 </apex:page>

Controller:

public class dynamicpickone{
//Constructor
public dynamicpickone() {

Parent = new Parent__c();
pickOptions = new List<SelectOption>();

// Use DescribeFieldResult object to retrieve commodities field.
// statusFieldDescription=sFD
Schema.DescribeFieldResult sFD = Parent__c.commodities__c.getDescribe();

// For each picklist value, create a new select option
//picklistEntry=plE
for (Schema.Picklistentry plE:sFD.getPicklistValues()){

pickOptions.add(new SelectOption(plE.getValue(),plE.getLabel()));

// obtain and assign default value
//if (picklistEntry.defaultValue){
// Parent.commodities__c = pickListEntry.getValue();
// }
}
}

Type 5:Usage of Dynamic picklist in vf & Apex

Type 5:Usage of Dynamic picklist in vf & Apex

Advertisements

One thought on “Type 5:Usage of Dynamic picklist in vf & Apex

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s