The below code explains, create picklist values and set a default value in the visual force page with apex class.
Step 1: Create visualforce page with the following code.
<apex:page controller=”SettingDefaultPicklist”>
<apex:form >
<apex:selectList value=”{!str}” size=”1″ multiselect=”false”>
<apex:selectOptions value=”{!TimingList}“>
</apex:selectOptions>
</apex:selectList>
</apex:form>
</apex:page>
Step 2: Create apex class with the below code.
public class SettingDefaultPicklist {
//Initialization
public string str {get; set;}
public List<SelectOption> TimingList=new List<SelectOption>();
//Constructor
public SettingDefaultPicklist() {
str = ‘09.30 am to 12.30pm’;
}
//SelectOption method
public List<SelectOption> getTimingList () {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption(‘01.30 am to 06.30pm’,’01.30 am to 06.30pm’));
options.add(new SelectOption(‘12.30 am to 1.30pm’,’12.30 am to 1.30pm’));
options.add(new SelectOption(‘09.30 am to 12.30pm’,’09.30 am to 12.30pm’));
return options;
}
}
Result:-
We are the ISV Partners and Please reach us for custom development => www.merfantz.com
———————————– *****Thank You*****—————————————-