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
SarisfdcSarisfdc 

Display text field value in picklist form on VF page

I have a custom object Custom_object__c having a text field Text__c. I want to display value of the text field of all records of the custom object in the form of picklist on VF page. I need only value (not binded with the record id). I want this picklist to create a page where I can dispaly record with filter option(as filter i want to use this picklist).
Please suggest how I can accomplish this.

Thanks!
Best Answer chosen by Sarisfdc
AshlekhAshlekh
Hi 

Here is simple code 
public string UserSelectVAlue {set;get;}
public ListOption<SelectOption> getListVal()
{
	ListOption<SelectOption> listValues = new List<SelectOption>();
	listValues.add(new SelectOption('','--None--'));
	for(Custom_object__c s: [select Text__c from Custom_object__c where Text__c != null limit 200])
	{
		listValues.add(new SelectOption(c.Text__c,c.Text__c));
	}
	return listValues;
}



<apex:selectList value="{!UserSelectVAlue}" multiselect="false" size="1">
            <apex:selectOptions value="{!ListVal}"/>
</apex:selectList><p/>

Salesforce has provide a good knowledge doc on this.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm

-Thanks
Ashlekh Gera

All Answers

Cloud_forceCloud_force
You can build custom picklist on VF page. You can use selection option /select list vf component to build this
here is a article on building custom picklist in VF page : http://www.cloudforce4u.com/2013/06/how-to-implement-custom-picklist-in.html
AshlekhAshlekh
Hi 

Here is simple code 
public string UserSelectVAlue {set;get;}
public ListOption<SelectOption> getListVal()
{
	ListOption<SelectOption> listValues = new List<SelectOption>();
	listValues.add(new SelectOption('','--None--'));
	for(Custom_object__c s: [select Text__c from Custom_object__c where Text__c != null limit 200])
	{
		listValues.add(new SelectOption(c.Text__c,c.Text__c));
	}
	return listValues;
}



<apex:selectList value="{!UserSelectVAlue}" multiselect="false" size="1">
            <apex:selectOptions value="{!ListVal}"/>
</apex:selectList><p/>

Salesforce has provide a good knowledge doc on this.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm

-Thanks
Ashlekh Gera
This was selected as the best answer