You need to sign in to do that
Don't have an account?
krishnag
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.
Have you tried adding the next arguments to your selectList?
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
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
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>
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
Jan,
I missed that,sorry about it.
Thanks
Gopi
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.
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
so when i execute this this is displaying as as a list instead of giving dropdown
Have you tried adding the next arguments to your selectList?
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.
thanks for the solution thats small attribute made me mad.:manmad: