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
Jagannatha Reddy BandaruJagannatha Reddy Bandaru 

I want to set default picklist value in visualforce page using apex code

i have created a picklist in vf page i.e.,like locations field in that when i select a location i want to display related records regarding locations ok that's fine,

after that one when i load the page i want to display by default particular location records that is also fine but i am not getting the location name in the picklist field

it is displaying none only. how should i get that one with out selecting a location.
Surya KiranSurya Kiran
Set the value in constructor
Vinit_KumarVinit_Kumar
Agrees set the Value in Constructor.Go through below sample code :-

VF page :-

<apex:page controller="sampleCon">
    <apex:form>
        <apex:selectList value="{!str}" size="0">
            <apex:selectOptions value="{!Countries}"/>
        </apex:selectList>
    </apex:form>
</apex:page>

Apex Class :-

public class sampleCon{
    public string str {get; set;}
    public List<SelectOption> lstCountries {get; set;}
    
    public sampleCon(){
        str = 'MEXICO';
    }
    public List<SelectOption> getCountries() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('US','US'));
        options.add(new SelectOption('CANADA','Canada'));
        options.add(new SelectOption('MEXICO','Mexico'));
        return options;
    }   
}


SAKTHIVEL MSAKTHIVEL M
Displaying Default Picklist Value On Visualforce Page Using Apex Class Controller

http://theblogreaders.com/displaying-default-picklist-value-visualforce-page-using-apex-class-controller/

Thanks & Regards,
-TheBlogReaders.com