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
Cable Guy.ax375Cable Guy.ax375 

Dynamically Building Month and Year Dropdown

Does anyone have existing code of dynamically building a dropdown in controller so that on the visualforce page would look like this (it always starts from current month and current year) for the next 24 months:

 

Aug-2010

Sep-2010

Oct -2010

Nov-2010

Dec-2010

Jan-2011

Feb-2011

Mar-2011

...

...

 

with value:

8-2010

9-2010

10-2010

11-2010

12-2010

1-2011

2-2011

3-2011

...

...

 

 

Any help will be greatly appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

You can easily create dropdown list in visual force page using <apex:selectList/> and <apex:selectOptions> componemts of VF page. For an example :

 

<apex:selectList value=”{!optin}” id=”myList”>

<apex:selectOptions value=”{!optionsList}” />

</apex:selectList>

 

Here “option” is the property of controller which would hold the selected value of picklist, and “option List” is the list of dates generated in controller.

 

Hope this helps.

All Answers

Pradeep_NavatarPradeep_Navatar

You can easily create dropdown list in visual force page using <apex:selectList/> and <apex:selectOptions> componemts of VF page. For an example :

 

<apex:selectList value=”{!optin}” id=”myList”>

<apex:selectOptions value=”{!optionsList}” />

</apex:selectList>

 

Here “option” is the property of controller which would hold the selected value of picklist, and “option List” is the list of dates generated in controller.

 

Hope this helps.

This was selected as the best answer
Cable Guy.ax375Cable Guy.ax375

Thanks. But I need to dynamically build this dropdown. Therefore, no hardcoding.