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
krishnagkrishnag 

a single select picklist in VF page

hi I know this is a foolish question but i am blank with this, How to create a single select picklist in a VF page.WHat is the apex tag we use for that.

I used <apex:selectlist> but its diplaying the list view.I am not getting dropdown for that.

Best Answer chosen by Admin (Salesforce Developers) 
JeeedeeeJeeedeee

Have you tried adding the next arguments to your selectList?

<apex:selectList size="1" multiselect="false"

 

Hope it does what you want, I don't exactly know what you're meaning with picklist, and maybe you can give a screenshot/link how you would like to have.

All Answers

JeeedeeeJeeedeee

Hi, this is what I used for a picklist, to remove the none option :)

 

Visual force

[code]

<apex:selectList size="1" multiselect="false" id="status" value="{!status}">
      <apex:selectOptions value="{!statusses}"></apex:selectOptions>
</apex:selectList>
[/code]

 

Controller

[code]

    private String status = null;
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String statusNew) {
        this.status = statusNew;
    }


    public List<SelectOption> getStatusses() {
        List<selectOption> options = new List<selectOption>();
        System.debug('In getstatusses');
        Schema.DescribeFieldResult field = Schema.sObjectType.Account.fields.Status__c;
        List<Schema.PicklistEntry> picklist = field.getPicklistValues();
        for(Schema.PicklistEntry p : picklist) {
            if(p.isDefaultValue() && getStatus() == null) {
                setStatus(p.getLabel());
            }
            SelectOption so = new Selectoption(p.getLabel(), p.getLabel());
            options.add(so);
        }
        System.debug('Options size ' +options.size());
        return options;
    }
[/code]

 

Hope it helps

 

 

gv007gv007

Krishna,

               there is minior modification in the above VF cod make multiselect is false then you are select only one picklist.The above method is used if you want get the picklist values from a table .
otherwise just use <option> html tag.

 

<apex:selectList size="1"  id="status" value="{!status}"

multiselect="false">
      <apex:selectOptions value="{!statusses}"></apex:selectOptions>
</apex:selectList>

JeeedeeeJeeedeee

Hi Gopi,

You are correct bout the option tag indeed, that's the simpel way. Why have the multiselect twice? It was also already in the code above, or did you missed that one probably?

Jan-Dirk

gv007gv007

Jan,

        I missed that,sorry about it.

Thanks

Gopi

krishnagkrishnag

i tried this even before as i mentioned in my question. I used the select list.THe problem is its not giving me the dropdown option.

krishnagkrishnag

My exact purpose for this is I am have a form where i have a field country.I need to display the picklist where i am mentioning all the countries as options as 

<apex:selectList value="{!state}" title="state" required="true" id="state" style="width:200px" >
                    <apex:selectOption itemLabel="Alaska" itemValue="Alaska"/>
                    <apex:selectOption itemLabel="Alabama" itemValue="Alabama"/>
                    <apex:selectOption itemLabel="Arkansas" itemValue="Arkansas"/>
                    <apex:selectOption itemLabel="Arizona" itemValue="Arizona"/>

 so when i execute this this is displaying as as a list instead of giving dropdown

 

JeeedeeeJeeedeee

Have you tried adding the next arguments to your selectList?

<apex:selectList size="1" multiselect="false"

 

Hope it does what you want, I don't exactly know what you're meaning with picklist, and maybe you can give a screenshot/link how you would like to have.

This was selected as the best answer
krishnagkrishnag

thanks for the solution thats small attribute made me mad.:manmad: