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
himanshu huske 7himanshu huske 7 

VF Task

Pick list using select option from apex.  VFpage + controller code
Biswojeet Ray 11Biswojeet Ray 11

Hi Himanshu,

Here I am putting some color names in List "Allvalues ". Then I am putting all color values in the pick list.

VF page code - 

<apex:page controller="PickList_Page_Controller">
    <apex:form >
        <apex:pageBlock >
            <apex:selectList value="{!val}" size="1">
                <apex:selectOptions value="{!ListValues}"></apex:selectOptions>
            </apex:selectList>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller Code - 
 
public with sharing class PickList_Page_Controller {

    public String val { get; set; }
    
    public List<String> Allvalues {get;set;}
    public List<SelectOption> ListValues {get;set;}
    
    public PickList_Page_Controller(){
        Allvalues = new List<String>{'None', 'Red', 'Pink', 'Black','Orange', 'blue', 'Green'};
        ListValues = new List<SelectOption>();
        for(String s : Allvalues){
            ListValues.add(new SelectOption(s, s));
        }
    }
}

I  hope it helps you.

Kindly let me know if it helps you and please mark as Best Answer.

Thanks and Regards,
Biswojeet,
Ajay K DubediAjay K Dubedi
Hi himanshu,
 
VF-PAGE:
<apex:page controller="SelectOptionList ">
    <apex:form >
    <apex:selectList size="1" value="{!selectedname}">
     <apex:selectOptions value="{!selectedname.Id}"/>  
        <apex:selectOptions value="{!selectedname.Name}"/>  
         <apex:selectOptions value="{!selectedname.Phone}"/>  
    </apex:selectList>
    </apex:form>
</apex:page>

CONTROLLER:
public class SelectOptionList {
    public string selectedname{get;set;}
        Public List<Selectoption> getselectedaccnamefields(){
            List<Selectoption> accList = new List<selectoption>();
            accList.add(new selectOption('', '- None -'));
            for(Account acc :[SELECT id,name,phone,type,industry FROM Account]){
            accList.add(new selectoption(acc.id,acc.name));
            }
            return accList;
        }
}

Try following code helps for you:

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi

 
jaliy maxjaliy max
Hi Himanshu,
Here (https://modapk.pro/4liker-apk/) I am putting some color names in List "All values ". Then I am putting all color values in the pick list.
VF page code - 
view sourceprint?
1<apex:page controller="PickList_Page_Controller">
2    <apex:form >
3        <apex:pageBlock >
4            <apex:selectList value="{!val}" size="1">
5                <apex:selectOptions value="{!ListValues}"></apex:selectOptions>
6            </apex:selectList>
7        </apex:pageBlock>
8    </apex:form>
9</apex:page>