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

Not getting the desired output - plz help me out
Output should be like this..
if we select DeptName from dropdown then all the details(deptno,loc) of that particular "dept name" should be displyed by quering the records from the "custom object"....
in the below code, "dept" is the custom object..
I tried like this but didnt get the required output.
///////////////////////////////////////////////////////
public class DeptDropDownCon
{
string dept;
public List<selectoption> getItems(){
List<selectoption> dept = new List<selectoption>();
dept.add(new selectoption('SPORTS','SPORTS'));
dept.add(new selectoption('SALES','SALES'));
return dept;
}
public PageReference test() {
return null;
}
public void setDept(string dept)
{
this.dept=dept;
}
public List<dept__c> getDept()
{
return[select name,loc__c from dept__c];
}
}
//////////////////////////////////////////////////////
<apex:page controller="DeptDropDownCon">
<apex:form >
<apex:selectList value="{!dept}" size="1">
<apex:selectOptions value="{!items}"/>
</apex:selectList><p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
<apex:outputPanel id="out">
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel >
<p>You have selected:</p>
<apex:dataTable value="{!dept}" var="d" width="50%" >
<apex:column VAlue="{!d.ID}" headerValue="dept ID"/>
<apex:column VAlue="{!d.name}" headerValue="dept Name"/>
<apex:column VAlue="{!d.LOC__c}" headerValue="dept location"/>
<!-- <apex:column VAlue="{!d.DEPTNO__c}" headerValue="dept no"/> -->
</apex:dataTable>
<!-- <apex:outputText value="{!dept}"/> -->
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:page>
/////////////////////////////////////////////////////////////////
with the above controller and the VF page, the same dept details will be displayed for all deptnames before click on test(immediately after saving)..
dept details should be displayed only after I select the "deptname" and click on test..
I will be waiting for ur reply..
tc..
Hi,
just replace the line-35 with following statement -
return [select name,loc__c from Dept__c where name =: dept];
All Answers
Hi,
I guess, you forgot to add filter in your query, so it returns every time same records.
Thank u for ur valuable reply.
But here I want to display the required specific dept details only when I select that particular dept in the drop down list.
plz once look at the below pic..
can u plz post your controller code also ?
small mistake..
once observe the code in the comments at the end of the controller ...
Hi,
just replace the line-35 with following statement -
return [select name,loc__c from Dept__c where name =: dept];
oh sorry !
it's not line no 35, it is line 28.
Yahoooooooo!!
got the output ..
Thank u so much Sir :)
If u dont mind , would u plz explain " name=:dept " ?
return [select name,loc__c from Dept__c where name =: dept];