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
.Net Api.Net Api 

dynamically dropdownlist

HI,

         how to create a dropdownlist in apex and i want to get the values into it dynamically. please help me.

 

Regards,

kranthi nagisetty

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

The selected value is applied to the controller through a merge field on the value attribute.

 

E.g.

 

Controller

 

 

public String selected {get; set;}

 

 

Page

 

 

 

<apex:selectList value="{!selected}">
   <apex:selectOptions value="{!options}"/>
</apex:selectList>

 

 

All Answers

bob_buzzardbob_buzzard

You can build the list of selectoptions that are available to the list via apex.

 

E.g. controller

 

 

public List<SelectOption> getOptions()
{
   List<SelectOption> options=new List<SelectOption>();
   list.add(new SelectOption('MyValue1', 'MyLabel1');
   list.add(new SelectOption('MyValue2', 'MyLabel2');
   list.add(new SelectOption('MyValue3', 'MyLabel3');

   return options;
}

 

 

Page:

 

 

<apex:selectList value="{!mySelectedOption}">
   <apex:selectOptions value="{!options}"/>
</apex:selectList>

 

 

 

 

.Net Api.Net Api

Thanks bob,

                     i got the binding but how to get the selected value and i want to save the selected value of dropdown into database please suggest how can i do this

bob_buzzardbob_buzzard

The selected value is applied to the controller through a merge field on the value attribute.

 

E.g.

 

Controller

 

 

public String selected {get; set;}

 

 

Page

 

 

 

<apex:selectList value="{!selected}">
   <apex:selectOptions value="{!options}"/>
</apex:selectList>

 

 

This was selected as the best answer
.Net Api.Net Api

Ok thanks ,

                      My issue resolved