You need to sign in to do that
Don't have an account?

I have different object like Country,State,District,Village If Click Country Like India it will automaticlly display the States,Districts,Villages
<apex:page controller="Dependentpicklist">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:selectList value="{!selectCountry}" size="1">
Country<apex:selectOptions value="{!Options}"/>
<apex:actionSupport event="onchange" action="{!FetchState}" reRender="OutState"/>
</apex:selectList>
<apex:outputPanel id="OutState">
<apex:selectList value="{!selectState}" size="1">
State<apex:selectOptions value="{!StateOptions}"/>
<apex:actionSupport event="onchange" action="{!FetchDistrict}" reRender="OutDist"/>
</apex:selectList>
<apex:outputPanel id="OutDist">
<apex:selectList value="{!selectDistrict}" size="1">
District<apex:selectOptions value="{!DistrictOptions}"/>
<apex:actionSupport event="onchange" action="{!FetchVillage}" reRender="OutVig"/>
</apex:selectList>
<apex:outputPanel id="OutVig">
<apex:selectList value="{!selectVillage}" size="1">
Village<apex:selectOptions value="{!VillageOptions}"/>
</apex:selectList>
</apex:outputPanel>
</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class Dependentpicklist{
public string selectCountry{set;get;}
public string selectState{set;get;}
public string selectDistrict{set;get;}
public string selectVillage{set;get;}
public List<Selectoption> Options{set;get;}
public List<Selectoption> StateOptions{set;get;}
public List<selectoption> DistrictOptions{set;get;}
public List<selectoption> VillageOptions{set;get;}
public Dependentpicklist(){
Options = new List<Selectoption>();
for(Country__c cou:[select Id,Name from Country__c]){
Options.add(new Selectoption(cou.Id,cou.Name));
}
}
public void FetchState(){
StateOptions = new List<Selectoption>();
for(State__c st:[select Id,Name from State__c where Country__c =:selectCountry]){
StateOptions.add(new Selectoption(st.Id,st.Name));
}
}
public void FetchDistrict(){
DistrictOptions = new List<Selectoption>();
for(District__c dis:[select Id,Name from District__c where State__c =:selectState]){
DistrictOptions.add(new Selectoption(dis.Id,dis.Name));
}
}
public void FetchVillage(){
VillageOptions = new List<Selectoption>();
for(Village__c vlg:[select Id,Name from Village__c where District__c =:selectDistrict]){
VillageOptions.add(new Selectoption(vlg.Id,vlg.Name));
}
}
}
if i select country before will be display NONE value .then if you select any country then automatically displays the states,districts,villages
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:selectList value="{!selectCountry}" size="1">
Country<apex:selectOptions value="{!Options}"/>
<apex:actionSupport event="onchange" action="{!FetchState}" reRender="OutState"/>
</apex:selectList>
<apex:outputPanel id="OutState">
<apex:selectList value="{!selectState}" size="1">
State<apex:selectOptions value="{!StateOptions}"/>
<apex:actionSupport event="onchange" action="{!FetchDistrict}" reRender="OutDist"/>
</apex:selectList>
<apex:outputPanel id="OutDist">
<apex:selectList value="{!selectDistrict}" size="1">
District<apex:selectOptions value="{!DistrictOptions}"/>
<apex:actionSupport event="onchange" action="{!FetchVillage}" reRender="OutVig"/>
</apex:selectList>
<apex:outputPanel id="OutVig">
<apex:selectList value="{!selectVillage}" size="1">
Village<apex:selectOptions value="{!VillageOptions}"/>
</apex:selectList>
</apex:outputPanel>
</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class Dependentpicklist{
public string selectCountry{set;get;}
public string selectState{set;get;}
public string selectDistrict{set;get;}
public string selectVillage{set;get;}
public List<Selectoption> Options{set;get;}
public List<Selectoption> StateOptions{set;get;}
public List<selectoption> DistrictOptions{set;get;}
public List<selectoption> VillageOptions{set;get;}
public Dependentpicklist(){
Options = new List<Selectoption>();
for(Country__c cou:[select Id,Name from Country__c]){
Options.add(new Selectoption(cou.Id,cou.Name));
}
}
public void FetchState(){
StateOptions = new List<Selectoption>();
for(State__c st:[select Id,Name from State__c where Country__c =:selectCountry]){
StateOptions.add(new Selectoption(st.Id,st.Name));
}
}
public void FetchDistrict(){
DistrictOptions = new List<Selectoption>();
for(District__c dis:[select Id,Name from District__c where State__c =:selectState]){
DistrictOptions.add(new Selectoption(dis.Id,dis.Name));
}
}
public void FetchVillage(){
VillageOptions = new List<Selectoption>();
for(Village__c vlg:[select Id,Name from Village__c where District__c =:selectDistrict]){
VillageOptions.add(new Selectoption(vlg.Id,vlg.Name));
}
}
}
if i select country before will be display NONE value .then if you select any country then automatically displays the states,districts,villages
try following code, it will help you
--
SamadhanForce