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
Sharathbabu KSharathbabu K 

adding values dynamically to the picklist

HII Freinds am bit new to salesforce,
I have an state__c sObject,if i create any sate in my state__c,created value should add dynamically to the pickist in visuaForce page
Any help would be greatly appriciated
Best Answer chosen by Sharathbabu K
nagendra 6989nagendra 6989

Hi Sharathbabu,

Please try the above code matching your requirement criteria.

VF Page:

 <apex:page controller="dynamicpicklistt">
  <apex:form>  
    <apex:pageblock>
       <apex:pageblocksection>
            <apex:outputlabel value="state" for="values" />
                      <apex:selectList value="{!satesize="1" id="values" >
                         <apex:actionSupport event="onchange" action="{!satetaction}" reRender="pb"/>
                      <apex:selectOptions value="{!stateNames}"/>
                  </apex:selectList>
            </apex:pageblocksectionItem>
     </apex:pageblock>
   </apex:form>
</apex:page>

Controller Page :

public dynamicpicklistt()
  {
    LocationNames = new List<selectoption>();
    LocationNames.add(new selectoption('Select state','Select state'));
    for(state__c l : [Select Id, Name FROM state__c])
          {
           LocationNames.add(new selectoption(l.id,l.name)); 
          }
   }

Thanks,
Please  mark it as solved if it helps you.......................

All Answers

nagendra 6989nagendra 6989

Hi Sharathbabu,

Please try the above code matching your requirement criteria.

VF Page:

 <apex:page controller="dynamicpicklistt">
  <apex:form>  
    <apex:pageblock>
       <apex:pageblocksection>
            <apex:outputlabel value="state" for="values" />
                      <apex:selectList value="{!satesize="1" id="values" >
                         <apex:actionSupport event="onchange" action="{!satetaction}" reRender="pb"/>
                      <apex:selectOptions value="{!stateNames}"/>
                  </apex:selectList>
            </apex:pageblocksectionItem>
     </apex:pageblock>
   </apex:form>
</apex:page>

Controller Page :

public dynamicpicklistt()
  {
    LocationNames = new List<selectoption>();
    LocationNames.add(new selectoption('Select state','Select state'));
    for(state__c l : [Select Id, Name FROM state__c])
          {
           LocationNames.add(new selectoption(l.id,l.name)); 
          }
   }

Thanks,
Please  mark it as solved if it helps you.......................
This was selected as the best answer
Sharathbabu KSharathbabu K
Hii nagendra babu 21,

Thanks for the reply your code was helpfull its working.