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
Sandy singhSandy singh 

how to hide selectList based on condition

Hi All,

 

Can any one tell me how to hide selectList based on condition if countries contain list value then show pickList else hide, below is my code:

 

VisualForce Code:

 <apex:outputText id="subTrip" rendered="{!countries.size >= 0}" >
     <apex:selectList id="list" value="{!country}" size="1">
    <apex:selectOptions value="{!countries}"  />
  </apex:selectList>
  </apex:outputText>

 

Controller Code:

public String country {get;set;}

public List<SelectOption> getCountries() {
            List<SelectOption> optetions = new List<SelectOption>();
            List<Country__c> items = [select Name,Id from Country__c where Id    =:selectedId ];
            for(Country__c c : items){
            options.add(new SelectOption(c.Id,c.Name));
                                    
           }

 

Thanks in Advance,

 

Regards,

Sandy

Sanchivan SivadasanSanchivan Sivadasan

You have pretty much everything right, except rendered="{!countries.size >= 0}. It should be rendered="{!countries.size >0}.

 

Did I answer your question? If yes please mark this as the solution. Thanks.

Sandy singhSandy singh

Hi,s

 

Here once use country.size, it always return size equal to 0, even this picklist contain some value, that's way  rendered="{!countries.size >0}" will always false. I don't understand what is wrong in this.

 

 

Regards,

Sandy

Andy BoettcherAndy Boettcher

You need to return a list in your GETer.

 

public String country {get;set;}
public List<SelectOption> getCountries() {
     List<SelectOption> optetions = new List<SelectOption>();
     List<Country__c> items = [select N...];
     for(Country__c c : items){
         options.add(new SelectOption(c.Id,c.Name));                           
     }

     // EDIT:  RETURN YOUR LIST
     return optetions;
     // END EDIT
}