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
jucuzoglujucuzoglu 

Conditional display of fields and block elements

I would like to display a different set of elements from an object depending on picklist value. If this were PHP and I could not use Case statements I might do something like:

 

If (myPicklistValue=='Value1')

{

// My webform fields to display if the value is 1

}

If (myPicklistValue=='Value2')

{

// My webform fields to display if the value is 2

}



If (myPicklistValue=='Value3')

{

// My webform fields to display if the value is 3

}

 I'd like to do something similar on a Visualforce page. Check the value of the picklist. If its equal to value1 then display a set of page and block elements etc...

 



Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You can do this using the rendered attribute available for most components, or you can wrap a set of components in an apex:outputPanel component.

 

For example:

 

<apex:outputPanel rendered="{!mypicklistvalue=='Value1'}">
   <apex:pageBlock title="Value 1 information">
     <!-- more stuff in here -->
   </apex:pageBlock>
</apex:outputPanel>

 

All Answers

bob_buzzardbob_buzzard

You can do this using the rendered attribute available for most components, or you can wrap a set of components in an apex:outputPanel component.

 

For example:

 

<apex:outputPanel rendered="{!mypicklistvalue=='Value1'}">
   <apex:pageBlock title="Value 1 information">
     <!-- more stuff in here -->
   </apex:pageBlock>
</apex:outputPanel>

 

This was selected as the best answer
Ankit AroraAnkit Arora

You can use Rendered in visualforce components to achieve this :

 

rendered="{!IF(condition = true , true , false)}"

 If condition is true then it will display a component else it won't.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Ankit AroraAnkit Arora

Oops!! Apologies, this is a cross post.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

bob_buzzardbob_buzzard

At least we both said the same thing :)