function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pankaj tiwari 13pankaj tiwari 13 

I have created a VF page where I am displaying two buttons - 'show all accounts', 'accounts with customer type direct'. And its working but now I need to use dropdown rather than buttons.

My controller is

public class c4
{
Account [] selectedacts;
public Account [] getselectedacts()
{
return selectedacts;
}
public PageReference showall()
{
selectedacts=[select Name, Type, Phone, Fax, Industry from Account];
return null;
}

public PageReference direct()
{
selectedacts=[select Name, Type, Phone, Fax, Industry from Account where Type='Customer - Direct'];
return null;
}

Public PageReference channel()
{
selectedacts=[select Name, Type, Phone, Fax, Industry from Account where Type='Customer - Channel'];
return null;
}

}

GauravGargGauravGarg
Hi Pankaj,

Thanks,

Gaurav
Skype: gaurav62990

pankaj tiwari 13pankaj tiwari 13

Here is my VF page that I have used for buttons

 

 

<apex:page controller="c4">
<apex:form >
 <apex:pageBlock title="List of Accounts">
 <apex:commandButton value="Show All Accounts" action="{!showall}" reRender="mytable"/>
 <apex:commandButton value="Show Direct Accounts" action="{!direct}" reRender="mytable"/>
 <apex:commandButton value="Show Channel Accounts" action="{!channel}" reRender="mytable"/>
 <apex:pageBlockTable value="{!selectedacts}" var="a" id="mytable">
 <apex:column value="{!a.Name}"/>
 <apex:column value="{!a.Type}"/>
 <apex:column value="{!a.Phone}"/>
 <apex:column value="{!a.Fax}"/>
 <apex:column value="{!a.Industry}"/>
 </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
</apex:page>
 

Shiva RajendranShiva Rajendran
Hello Pankaj,

I have added my working code which matches your requirement.
<apex:page controller="c4">
  
  
  <apex:form >
      <apex:selectList size="1" value="{!userChosenValue}">
      <apex:selectOptions value="{!selectOptionValues}"></apex:selectOptions>     
       <apex:actionSupport event="onchange"   action="{!changeData}" reRender="changeInnerData" /> 
 
      </apex:selectList>
      <br/>
        <apex:outputPanel id="changeInnerData">
            <apex:repeat value="{!accountList}" var="acc1">
                     
                {!acc1.name} +" "+{!acc1.type} +" "+{!acc1.id} <br/>
            </apex:repeat>
            <apex:actionStatus id="counterStatus" 
                                   startText=" (incrementing...)" 
                                   stopText=" (done)"/>
              </apex:outputPanel>
  </apex:form>
</apex:page>
public class c4 {
public List<Account> typ1Accounts {get;set;}
public List<Account> typ2Accounts {get;set;}
    public List<Account>           accountList{get;set;} 

    public string userChosenValue{get;set;}
    public SelectListVf_CC()
    {
        typ1Accounts=[select id,type,name from account where type='Prospect'];
        typ2Accounts=[select id,type,name from account where type='Customer - Direct'];
        accountList=typ1Accounts;
        userChosenValue='Prospect';
    }
    
    public List<SelectOption> selectOptionValues
    {
        get{
        selectOptionValues=new List<SelectOption>();
        selectOptionValues.add(new SelectOption('Prospect','Prospect'));
                    selectOptionValues.add(new SelectOption('Customer - Direct','Customer - Direct'));

            return selectOptionValues;
        }
        set;     
        
    }
    public void changeData()
    {
        if(userChosenValue=='Prospect')
            accountList=typ1Accounts;
        else
            accountList=typ2Accounts;
        
    }
    
  
}

Hope this helps..Let me know if you need further help

Thanks and Regards,
Shiva RV
pankaj tiwari 13pankaj tiwari 13

Thanks, Shiva!

It works.