Hi,
Dependent picklists in Salesforce are very useful. They are used to limit the list of values in one picklist based on the value of another picklist.
An example would be if you had a list of countries and states/provinces . If you select a country you would want the list of states/provinces to be filtered in the next picklist.
Visualforce page
<apex:page controller="DependentPicklistExpClass">
<apex:form>
<apex:pageblock>
<apex:pageblocksection columns="2">
<apex:pageblocksectionitem>
<apex:outputlabel value="Country">
</apex:outputlabel>
</apex:pageblocksectionitem>
<apex:pageblocksectionitem>
<apex:selectlist size="1" value="{!country}">
<apex:selectoptions value="{!countries}"></apex:selectoptions>
<apex:actionsupport event="onchange" rerender="a"></apex:actionsupport>
</apex:selectlist>
</apex:pageblocksectionitem>
<apex:pageblocksectionitem>
<apex:outputlabel value="State"></apex:outputlabel>
</apex:pageblocksectionitem>
<apex:pageblocksectionitem>
<apex:selectlist size="1" value="{!state}" id="a">
<apex:selectoptions value="{!states}"></apex:selectoptions>
</apex:selectlist>
</apex:pageblocksectionitem>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
Apex Class
public class DependentPicklistExpClass {
public String country{get;set;}
public String state{get;set;}
public List getCountries()
{
list options=new list();
options.add(new SelectOption('none','countries'));
options.add(new SelectOption('US','United States'));
options.add(new SelectOption('IN','India'));
return options;
}
public list getStates()
{
list options=new list();
if(country=='US')
{
options.add(new SelectOption('none','states'));
options.add(new SelectOption('st1','State1'));
options.add(new SelectOption('st2','State2'));
}
else if(country=='IN')
{
options.add(new SelectOption('none','states'));
options.add(new SelectOption('UP','Uttar Pradesh'));
options.add(new SelectOption('UK','Uttarakhand'));
}
else
{
options.add(new SelectOption('none','states'));
}
return options;
}
}