Skip to main content
improved
Source Link
highfive
  • 6.3k
  • 3
  • 32
  • 58

You have to populate a List<SelectOption> to bind with the UI. Also have a variable to grab which have been selected from the select options. In your controller have below codes

public String selectedVal{get;set;}  // This will hold the selected value, the id in here

public List<SelectOption> getopenPresentationOptions(){
        List<SelectOption> optns = new List<Selectoption>();
        optns.add(new selectOption('a09N0000002R0oeIAC', 'First// Name'));
before getting here you must populate your queryResult optns.add(newlist selectOption('a09N0000002R0p4IAC',with 'Secondrequired Name'));fields
        optns.addfor(newYour_Object selectOption('a09N0000002R0dpIAC',obj 'Third: Name')queryResult);{
           optns.add(new selectOption('a09N0000003LxoEIAS'obj.Id, 'Fourth Name'obj.Name));
        }            
        
        return optns;
}

VF Page:

<apex:selectList value="{!selectedVal}" size="1"> 
    <apex:selectOptions value="{!openPresentationOptions}" /> 
</apex:selectList>

UPDATE : added code so that selectoptions list will be populated with a query result

You have to populate a List<SelectOption> to bind with the UI. Also have a variable to grab which have been selected from the select options. In your controller have below codes

public String selectedVal{get;set;}  // This will hold the selected value, the id in here

public List<SelectOption> getopenPresentationOptions(){
        List<SelectOption> optns = new List<Selectoption>();
        optns.add(new selectOption('a09N0000002R0oeIAC', 'First Name'));
        optns.add(new selectOption('a09N0000002R0p4IAC', 'Second Name'));
        optns.add(new selectOption('a09N0000002R0dpIAC', 'Third Name'));
        optns.add(new selectOption('a09N0000003LxoEIAS', 'Fourth Name'));            
        
        return optns;
}

VF Page:

<apex:selectList value="{!selectedVal}" size="1"> 
    <apex:selectOptions value="{!openPresentationOptions}" /> 
</apex:selectList>

You have to populate a List<SelectOption> to bind with the UI. Also have a variable to grab which have been selected from the select options. In your controller have below codes

public String selectedVal{get;set;}  // This will hold the selected value, the id in here

public List<SelectOption> getopenPresentationOptions(){
        List<SelectOption> optns = new List<Selectoption>();
        // before getting here you must populate your queryResult list with required fields
        for(Your_Object obj : queryResult){
           optns.add(new selectOption(obj.Id, obj.Name));
        }            
        
        return optns;
}

VF Page:

<apex:selectList value="{!selectedVal}" size="1"> 
    <apex:selectOptions value="{!openPresentationOptions}" /> 
</apex:selectList>

UPDATE : added code so that selectoptions list will be populated with a query result

Source Link
highfive
  • 6.3k
  • 3
  • 32
  • 58

You have to populate a List<SelectOption> to bind with the UI. Also have a variable to grab which have been selected from the select options. In your controller have below codes

public String selectedVal{get;set;}  // This will hold the selected value, the id in here

public List<SelectOption> getopenPresentationOptions(){
        List<SelectOption> optns = new List<Selectoption>();
        optns.add(new selectOption('a09N0000002R0oeIAC', 'First Name'));
        optns.add(new selectOption('a09N0000002R0p4IAC', 'Second Name'));
        optns.add(new selectOption('a09N0000002R0dpIAC', 'Third Name'));
        optns.add(new selectOption('a09N0000003LxoEIAS', 'Fourth Name'));            
        
        return optns;
}

VF Page:

<apex:selectList value="{!selectedVal}" size="1"> 
    <apex:selectOptions value="{!openPresentationOptions}" /> 
</apex:selectList>