You need to sign in to do that
Don't have an account?
Naresh Kumar Mohan Thirukkovaluru
how to get connected to sbjects thru controller class for getting states & its capitals
public with sharing class sample {
public List<selectoption> getCities() {
List<selectoption> op1= new List<selectoption> ();
if(state == 'AP')
{
List<dependncs__c> rt = [select city__c from dependncs__c];
string nb;
for(dependncs__c c : rt)
nb=c.city__c;
op1.add(new selectoption(nb,nb));
}
else if(state == 'TN')
{
//op1.add(new selectoption('CHEN','CHENNAI'));
}
else
{
//op1.add(new SelectOption('None','--- None ---'));
}
return op1;
}
public String city { get; set; }
public List<selectoption> getStates() {
List<dependncs__c> rt = [select state__c from dependncs__c];
List<selectoption> op= new List<selectoption> ();
string na;
for(dependncs__c b:rt){
na=b.state__c;
op.add(new selectoption(na,na));
}
return op;
}
public String state { get; set; }
}
VF
<apex:page controller="sample">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns="2">
<apex:pageblockSectionItem >
<apex:outputLabel value="State"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!state}">
<apex:selectOptions value="{!states}"/>
<apex:actionSupport event="onchange" reRender="a"/>
</apex:selectList>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="City"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!city}" id="a">
<apex:selectOptions value="{!cities}"/>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public List<selectoption> getCities() {
List<selectoption> op1= new List<selectoption> ();
if(state == 'AP')
{
List<dependncs__c> rt = [select city__c from dependncs__c];
string nb;
for(dependncs__c c : rt)
nb=c.city__c;
op1.add(new selectoption(nb,nb));
}
else if(state == 'TN')
{
//op1.add(new selectoption('CHEN','CHENNAI'));
}
else
{
//op1.add(new SelectOption('None','--- None ---'));
}
return op1;
}
public String city { get; set; }
public List<selectoption> getStates() {
List<dependncs__c> rt = [select state__c from dependncs__c];
List<selectoption> op= new List<selectoption> ();
string na;
for(dependncs__c b:rt){
na=b.state__c;
op.add(new selectoption(na,na));
}
return op;
}
public String state { get; set; }
}
VF
<apex:page controller="sample">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns="2">
<apex:pageblockSectionItem >
<apex:outputLabel value="State"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!state}">
<apex:selectOptions value="{!states}"/>
<apex:actionSupport event="onchange" reRender="a"/>
</apex:selectList>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="City"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!city}" id="a">
<apex:selectOptions value="{!cities}"/>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Reference in visualforce as:
i want to get states and their capitals as i inserted records TN=chen, AP=hyd
so i got states list in my page their corresponding capitals i m unable to get thru controller clas