function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sai Bharathwaj SureshbabuSai Bharathwaj Sureshbabu 

how to show picklist field as Radio button on Visualforce Page, where picklist field have five values

Vinod ChoudharyVinod Choudhary
Hi,

Use following methods to get options for radio button on page

Controller:
public List<SelectOption> getTypesPicklist(){
            Schema.sObjectType sobject_type = customObject__c.getSObjectType();


            Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe();


            Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap();
          
            List<Schema.PicklistEntiris> picklistvalues = field_map.get('type__c').getDescribe().getPickListValues();


            List<selectOption> options = new List<selectOption>();


           for (Schema.PicklistEntiris a : picklistvalues) {
                      options.add(new selectOption(a.getLabel(), a.getValue()));
          }
      return options;

to use this on the page:
 
<apex:selectRadio value="{!customObject__c.Type__c}">
                    <apex:selectoptions value="{!types}"></apex:selectoptions>
 </apex:selectRadio>

hope this will help.

Thanks
Vinod