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
SFDC16SFDC16 

How to set picklist value from vf page ?

Hello Developers,

Whenever I created a product from the visualforce page I want set picklist value. In product object, I created one picklist filed name like product_type__c. Simply I want to create a product from vf page and for that product, I have to set product type. 

Regards,
SFDC16
Administrator Hacker 17Administrator Hacker 17
HI
MUHAMMED SEMIN P NMUHAMMED SEMIN P N
Hi SFDC16,
code given below will help you...
 
Visual force Page:

<apex:pageBlockSection title="Custom Picklist Using selectList and selectOption" collapsible="false">
            <apex:selectList value="{!selectedType}" multiselect="false" size="1">
                <apex:selectOption itemValue="Mobile" itemLabel="Mobile"/>
                <apex:selectOption itemValue="laptop" itemLabel="laptop"/>
                <apex:selectOption itemValue="calculator" itemLabel="calculator"/>
            </apex:selectList>
<apex:pageBlockSection>

Apex Code:

public String selectedType{get;set;}
if it solve your question, please mark it as a best answer!!!
thanks,,
 
Ajay K DubediAjay K Dubedi
Hi SFDC,

You can try the following code :

Controller :
public class productselect{
public String selectedVal{get;set;} 

public list<SelectOption> getProductnames()
{
  list<SelectOption> soList = new list<SelectOption>();
  soList.add(new SelectOption('', '- None -'));
  for(Product prod : [Select Id, product_type__c from Product LIMIT 1000])
  soList.add(new SelectOption(prod.id, Prod.product_type__c));
  return soList;
}
}
VF page :
<apex:page controller="productselect">
<apex:form >
<apex:selectList value="{!selectedVal}" size="1"> 
<apex:selectOptions value="{!Productnames}" /> 
</apex:selectList>
</apex:form>
</apex:page>


Please mark as best answer if it helps you.

Thank You, 
Ajay Dubedi