You need to sign in to do that
Don't have an account?
sourabh kalva
can we write the same code without the command buttons and get the record from sobject
VF page;
<apex:page controller="customPickListInVFDemoController" tabStyle="Account">
<apex:form >
<apex:pageBlock title="Custom PickList Demo" id="out">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" rerender="out" status="actStatusId"/>
<apex:actionStatus id="actStatusId">
<apex:facet name="start">
<img src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Custom Picklist Using selectList and selectOption" collapsible="false">
<apex:selectList value="{!selectedCountry1}" multiselect="false" size="1">
<apex:selectOption itemValue="INDIA" itemLabel="India"/>
<apex:selectOption itemValue="USA" itemLabel="USA"/>
<apex:selectOption itemValue="United Kingdom" itemLabel="UK"/>
</apex:selectList>
<apex:outputText value="{!selectedCountry1}" label="You have selected:"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Custom Picklist Using selectList and selectOptions" collapsible="false">
<apex:selectList value="{!selectedCountry2}" multiselect="false" size="1">
<apex:selectOptions value="{!countriesOptions}"/>
</apex:selectList>
<apex:outputText value="{!selectedCountry2}" label="You have selected:"/>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
controller;
public class customPickListInVFDemoController {
public String selectedCountry1{get;set;}
public String selectedCountry2{get;set;}
public customPickListInVFDemoController(){
}
public List<SelectOption> getCountriesOptions() {
List<SelectOption> countryOptions = new List<SelectOption>();
countryOptions.add(new SelectOption('','-None-'));
countryOptions.add(new SelectOption('INDIA','India'));
countryOptions.add(new SelectOption('USA','USA'));
countryOptions.add(new SelectOption('United Kingdom','UK'));
countryOptions.add(new SelectOption('Germany','Germany'));
countryOptions.add(new SelectOption('Ireland','Ireland'));
return countryOptions;
}
public PageReference save(){
return null;
}
}
<apex:page controller="customPickListInVFDemoController" tabStyle="Account">
<apex:form >
<apex:pageBlock title="Custom PickList Demo" id="out">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" rerender="out" status="actStatusId"/>
<apex:actionStatus id="actStatusId">
<apex:facet name="start">
<img src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Custom Picklist Using selectList and selectOption" collapsible="false">
<apex:selectList value="{!selectedCountry1}" multiselect="false" size="1">
<apex:selectOption itemValue="INDIA" itemLabel="India"/>
<apex:selectOption itemValue="USA" itemLabel="USA"/>
<apex:selectOption itemValue="United Kingdom" itemLabel="UK"/>
</apex:selectList>
<apex:outputText value="{!selectedCountry1}" label="You have selected:"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Custom Picklist Using selectList and selectOptions" collapsible="false">
<apex:selectList value="{!selectedCountry2}" multiselect="false" size="1">
<apex:selectOptions value="{!countriesOptions}"/>
</apex:selectList>
<apex:outputText value="{!selectedCountry2}" label="You have selected:"/>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
controller;
public class customPickListInVFDemoController {
public String selectedCountry1{get;set;}
public String selectedCountry2{get;set;}
public customPickListInVFDemoController(){
}
public List<SelectOption> getCountriesOptions() {
List<SelectOption> countryOptions = new List<SelectOption>();
countryOptions.add(new SelectOption('','-None-'));
countryOptions.add(new SelectOption('INDIA','India'));
countryOptions.add(new SelectOption('USA','USA'));
countryOptions.add(new SelectOption('United Kingdom','UK'));
countryOptions.add(new SelectOption('Germany','Germany'));
countryOptions.add(new SelectOption('Ireland','Ireland'));
return countryOptions;
}
public PageReference save(){
return null;
}
}
Here command button using to save pickilist values ,
if you want to get by sObject then please follow below code:-
Apex class:-
VF Page:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh