+ Start a Discussion
Lavanya Ponniah 3Lavanya Ponniah 3 

How to auto populate the choosen picklist value to the other object picklist value in VF pages

nitesh gadkarinitesh gadkari
Hi Lavanya,

you can use <apex:SelectList> and <apex:selectoptions> tag for this purpose to achieve your goal.

 
Lavanya Ponniah 3Lavanya Ponniah 3
Hi Hitesh,
I want to use controller extension  for that
nitesh gadkarinitesh gadkari
Surely you have to use controller extensions for this.
Lavanya Ponniah 3Lavanya Ponniah 3
Can u give example code for  that.
nitesh gadkarinitesh gadkari
GIve me the exact scenario.I mean which picklist's value should get inserted in dynamic picklist
Lavanya Ponniah 3Lavanya Ponniah 3
I have Product_Services__c is the object having the picklist datatype as Product under that (Mobile VoIP,Softswitch & Billing Platform,Carrier Billing Solutions,Bandwidth Optimization,Other).Likewise in Contact__c object having the picklist datatype as Product under that (Mobile VoIP,Softswitch & Billing Platform,Carrier Billing Solutions,Bandwidth Optimization,Other). So when i choose the value in Product_Services__c it should reflect in Contact__c. This is my scenario.
nitesh gadkarinitesh gadkari
does both objects have relationships between them.What type?
praveen murugesanpraveen murugesan
Hi Lavanya,

Pls tell me wat is the relationship between Product_Services__c and Contact. There should be some realation then only we can query the Contact and assign the pick list value.

Thanks.

Praveen Murugesan


Lavanya Ponniah 3Lavanya Ponniah 3
No I want to use it in the VF page,for that i need controller.

praveen murugesanpraveen murugesan
Lavanya,

Try like this,
<apex:page controller="PickListController">
  <apex:form >
 
                    <apex:SelectList id="List" value="{!selectedcountry}" size="1">  <!-- selected value will stored in this variable -->
                        <apex:selectOptions value="{!lstoptions}"/> 
                    </apex:SelectList>
                    
       <!--             
      select <apex:selectList size="1" title="Country">
          <apex:selectOptions value="{!lstoptions}"></apex:selectOptions>
      </apex:selectList>  -->
     
  </apex:form>
</apex:page>
public with sharing class PickListController {

    public String selectedcountry { get; set; }

    public list<selectoption>  lstoptions { get; set; }
    
    public PickListController()
    {
      list<selectoption> options  = new list<selectoption>();
      options.add(new selectoption('','select country'));
      options.add(new selectoption('India','IND'));
      options.add(new selectoption('US','US'));
      options.add(new selectoption('Canada','CA'));
      lstoptions = options;
    
    }
}

then assign selectedcountry to the contact obj picklist field from the controller.

Mark this as best answer if its helps.

Thanks.

Praveen Murugesan