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
su tsu t 

Displaying Picklist value dynamically

Hi,

So I'm creating a VF page. There is a coustom object called XYZ. Its has a picklist Field abc. I want to display abc as picklist value on my page. What will the code be in the class. Please help.
KaranrajKaranraj
If you using standard controller, then simply give the api name of the field in the input visualforce tag. For example, below page will display the Lead statuc picklist field in a visualforce page
 
<apex:page standardController="Lead">
  <apex:form>
<apex:inputField value="{!Lead.Status}"/>
</apex:form>
</apex:page>

 
Vishnu VaishnavVishnu Vaishnav
Hi,

your code will be in the class:

public class mytest{
    public xyz__c xObj{get;set;}
    public mytest(){
       xObj = new xyz__c();
    }
}

VF Page will be::
<apex:page controller="mytest">
<apex:form>
<apex:inputField value="{!xObj.abc__c}"/>
</apex:form>
</apex:page>


:::======================================================================:::
Qusetion Solved ? then mark as best answer to make helpful to others .....
 
Anjali Sharma 87Anjali Sharma 87
Controller***********************

public with sharing class Picklistselect {

 public string selected{get;set;}
 
  public Picklistselect()
  {
    
  }
  
  public List<SelectOption> getpicklst()
  {
    List<SelectOption> option=new List<SelectOption>();
    List<Account> acclst=[Select Name,website from Account];
    
    option.add(new SelectOption('-None-','-None-'));
    for(Account ob:acclst)
    {
      option.add(new SelectOption(ob.id,ob.Name));
    }
    
    return option;
  }
}


****************************
Vf page

<apex:page controller="Picklistselect">
  <apex:form >
   <apex:pageBlock title="Choose Account from picklist">
    <apex:pageBlockSection >
     <apex:selectList value="{!selected}" size="1" label="Account">
      <apex:selectOptions value="{!picklst}">
                          
      </apex:selectOptions>
     </apex:selectList>
    </apex:pageBlockSection>
    
   </apex:pageBlock>
  </apex:form>
</apex:page>
su tsu t
Thabks a lot guys. Will try this today and let you all. But thanks again