Type 2:Usage of picklist in vf & Apex


Salesforce23

Example: Creating Picklist in Visualforce page (In Sobject its not Picklist)
Lets take an example that we have one Sobject Employee__c and the Field name  is EmpName(std field)

<apex:page controller=”vfpage2″ sidebar=”false” showHeader=”false”>
<apex:form >
<apex:selectList size=”1″ value=”{!selectedValue}”>
<apex:selectOptions value=”{!values}”/>
<apex:actionSupport event=”onchange” reRender=”one”/>
</apex:selectList>
<br/>
<apex:outputLabel id=”one”> <b> The selected Employee Name is : {!selectedValue}</apex:outputlabel>
</apex:form>
</apex:page>

Controller:
public class vfpage2 {
public String selectedValue { get; set; }
public List<selectoption> getValues() {
List< selectOption> ls= new list<selectOption>();
List<Employee__c> emp=[select empName from Employee__c];
for(Employee__c e:emp){
ls.add(new selectOption(e.empName,e.empName));
}
return ls;
}

}
OutPut:
one

View original post

Advertisements