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
sudhirn@merunetworks.comsudhirn@merunetworks.com 

How to make default value in select list

Hi, 

  In visual force page we are displaying picklist with Yes or No Option we need to make No as a default view on visual force page. Please suggest how to make the change on this code 
 
<apex:outputLabel value=" Renewal Opportunity" for="RenOpp"/> 
          <apex:selectList value="{!RenewalOpportunity}" multiselect="false" size="1">
             <apex:selectOptions value="{!RenewalOpp}" />
          </apex:selectList>

Thanks

Sudhir


 

Best Answer chosen by sudhirn@merunetworks.com
SivaGSivaG
Hi Sudhir,

When you use custom picklist you should not use the standard picklist. Just remove the below line from your code.

Replace this line 
<apex:selectOptions value="{!RenewalOpp}" />

with below 2 lines

<apex:selectOption itemValue="No" itemLabel="No"/>
 <apex:selectOption itemValue="Yes" itemLabel="Yes"/>

Thanks
Kumar

 

All Answers

SivaGSivaG
Hi Sudhir,

Are you displaying a custom picklist built in controller or a standard picklist field? If you are displaying a custom picklist then you can change the display order in VFP.

Thanks
Kumar
 
sudhirn@merunetworks.comsudhirn@merunetworks.com
By default blank value is showing how to make No as a default value 
SivaGSivaG
Hi Sudhir,

Try this and see if No appears as default value in VFP.
<apex:outputLabel value=" Renewal Opportunity" for="RenOpp"/> 
          <apex:selectList value="{!RenewalOpportunity}" multiselect="false" size="1">
              <apex:selectOption itemValue="No" itemLabel="No"/>
               <apex:selectOption itemValue="Yes" itemLabel="Yes"/>
          </apex:selectList>

PS: Please mark this as Best Anwer if it solves your problem.
sudhirn@merunetworks.comsudhirn@merunetworks.com

Hi Kumar, 

  I am using standard picklist from the object if i use your code it is duplicating the value displaying multiple times. 

Thanks

Sudhir

SivaGSivaG
Hi Sudhir,

When you use custom picklist you should not use the standard picklist. Just remove the below line from your code.

Replace this line 
<apex:selectOptions value="{!RenewalOpp}" />

with below 2 lines

<apex:selectOption itemValue="No" itemLabel="No"/>
 <apex:selectOption itemValue="Yes" itemLabel="Yes"/>

Thanks
Kumar

 
This was selected as the best answer
sudhirn@merunetworks.comsudhirn@merunetworks.com
Thanks Kumar removing that will not affect code to save the data right
SivaGSivaG
Hi Sudhir,

No issues. As you are asssigning it to the right variable RenewalOpportunity in Selectlist component.

Thanks
Kumar

PS: Please mark this as Best Anwer if it solves your problem.
 
Anupam Agarwal 17Anupam Agarwal 17
I have the below code written but the VF shows 'Yes' as the default option on pageLoad.

<apex:selectOption itemValue="" itemLabel="---None---" ></apex:selectOption>
<apex:selectOption itemValue="Yes" itemLabel="Yes"></apex:selectOption>
<apex:selectOption itemValue="No" itemLabel="No"></apex:selectOption>

I need to display None as default. Any pointers on this?
Harish RudrojuHarish Rudroju
You can Try as Below
 
<apex:outputLabel value=" Renewal Opportunity" for="RenOpp"/> 
          <apex:selectList value="{!RenewalOpportunity}" multiselect="false" size="1">
             <apex:selectOption itemvalue='No'/>
             <apex:selectOptions value="{!RenewalOpp}" />
          </apex:selectList>

 Thanks ..