Play Games

Search This Blog

Saturday, January 9, 2016

Display SelectList in Visualforce page

Display SelectList in Visualforce page

Apex Code:
public  class SelectList {
    Public String SelectedLocation{get;set;}
    public SelectList (ApexPages.StandardController controller) {

    }
 
    public List<SelectOption> getLocation() {
        List<SelectOption> locationOptions = new List<SelectOption>();
        locationOptions.add(new SelectOption('Hyderabad','Hyderabad'));
        locationOptions.add(new SelectOption('Kolkata','Kolkata'));
        locationOptions.add(new SelectOption('Pune','Pune'));
        locationOptions.add(new SelectOption('Mumbai','Mumbai'));
        locationOptions.add(new SelectOption('Delhi','Delhi'));
        return locationOptions;
    }
}
Visualforce Page:
<apex:page standardController="Account" extensions="SelectList ">
    <apex:form >
        <apex:pageblock >
            <apex:panelGrid columns="5">
                Select City &nbsp;<apex:selectList value="{!SelectedLocation}" multiselect="false" size="1">
                    <apex:selectOptions value="{!Location}"/>
                </apex:selectList>
             </apex:panelGrid>
        </apex:pageblock>
    </apex:form>
</apex:page>
Output:


No comments:

Post a Comment