You need to sign in to do that
Don't have an account?
sp13
multipicklist values to picklist in visualforce page
i created a picklist in visualforcepage with all the values of a mutilpicklist field from Course__c.
this is my code:
statusOptions = new List<SelectOption>(); // Use DescribeFieldResult object to retrieve status field. Schema.DescribeFieldResult statusFieldDescription = Course__c.Year_Block__c.getDescribe(); // For each picklist value, create a new select option for (Schema.Picklistentry picklistEntry: statusFieldDescription.getPicklistValues()) { statusOptions.add(new SelectOption( pickListEntry.getValue(),pickListEntry.getLabel())); // obtain and assign default value if (picklistEntry.defaultValue){ course.Year_Block__c = pickListEntry.getValue(); } }
i want to show in the picklist only the multipicklist values of one record.
example:
all multipicklist field values= 1, 2, 3, 4, 5
one record: name=Test ; multipicklist values=1, 3, 5
how can i show only 1,3,5 in the created picklist in vfpage?
Course__c var = [Select Id, Year_Block__c from Course__c where Id = :IdOfRecord];
for(String s: var.Year_block__c.split(';'))
statusOptions.add(new SelectOption(s, s));
All Answers
Hi ,
Please you use in this way, It will be helpful for you.
Visualforce Page:
<apex:selectList value="{!objectname.Course__c}" multiselect="false" size="1">
<apex:selectOptions value="{!course}"/>
</apex:selectList>
Controller:
public List<SelectOption> getcourse() {
List<SelectOption> courseOptions = new List<SelectOption>();
courseOptions.add(new SelectOption('1','1'));
courseOptions.add(new SelectOption('3','3'));
courseOptions.add(new SelectOption('5','5'));
return courseOptions ;
}
Course__c var = [Select Id, Year_Block__c from Course__c where Id = :IdOfRecord];
for(String s: var.Year_block__c.split(';'))
statusOptions.add(new SelectOption(s, s));