2

i want to create a picklist which contains account and contact..when we select account then it shows account list (name,website,email)..and when we select contact then it will shows contact list(name,mobile,email)..

i have alredy write below code but it not shows desired result

public class PickAccountContact{
 public string selectdMaster{get;set;}
 public List<contact> listcontacts{get;set;}
 public List<Account> listAccount{get;set;}

 public List<SelectOption> getMasterOption() {
   List<SelectOption> Options=new List<SelectOption>();
   options.add(new selectoption('Acc','Account'));
   options.add(new selectoption('Con','Contact'));
   return options;
 }
}

page:

<apex:page controller="PickAccountContact" sidebar="false">
  <apex:form >
    <apex:pageBlock >
      <apex:outputPanel >
        <apex:outputLabel value="Account/Contact"/>&nbsp;&nbsp;&nbsp;
        <apex:selectList value="{!selectdMaster}" size="1">
          <apex:selectOptions value="{!MasterOption}"/>
        </apex:selectList>
      </apex:outputPanel>
    </apex:pageBlock>
  </apex:form>
</apex:page>
1

You need to add actionsupport for event onchange.

<apex:page controller="PickAccountContact" sidebar="false">
  <apex:form >
    <apex:pageBlock >
      <apex:outputPanel >
        <apex:outputLabel value="Account/Contact"/>&nbsp;&nbsp;&nbsp;
        <apex:selectList value="{!selectdMaster}" size="1">
          <apex:selectOptions value="{!MasterOption}"/>
          <apex:actionSupport event="onchange" reRender="list,list2"/>
        </apex:selectList>
      </apex:outputPanel>
      <apex:outputPanel id="list" rendered="{!selectdMaster = 'Acc'}>
          <apex:pageBlockTable value="{!listAccount}" var="a">

            <apex:column value="{!a.name}"/> 
            <apex:column value="{!a.website}"/> 
            <apex:column value="{!a.email}"/> 
        </apex:pageBlockTable>
      </apex:outputPanel>
      <apex:outputPanel id="list2" rendered="{!selectdMaster = 'Con'}>
          <apex:pageBlockTable value="{!listcontacts}" var="c">

            <apex:column value="{!c.name}"/> 
            <apex:column value="{!c.mobile}"/> 
            <apex:column value="{!c.email}"/> 
        </apex:pageBlockTable>
      </apex:outputPanel>
    </apex:pageBlock>
  </apex:form>
</apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.