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
Sudhir_MeruSudhir_Meru 

Visual Force Conditional Display

Hi,

 

 I am new to visual force. I need to display the fields based on a condition.

 

There are fields like discount_program_c, deal_reg_c, nsp_c

 

example:

if discount_program_c = 'NSP' then

   nsp_c;

else

 deal_reg_c;

 

I need to show the fields conditionally. In visual force

 

Please suggest me a sample code how to show these fields conditioanlly.

 

Thanks

Sudhir

 

 

Cory CowgillCory Cowgill

Sudhir,

 

You can use the rendered attribute on Apex tags to conditionally render fields on a page.

 

For example

<apex:outputField value="{!object.nsp__c}" rendered="{!object.discount_program__c == 'NSP'}"/>

<apex:outputField value="{!object.deal_reg__c}" rendered="{!object.discount_program__c != 'NSP'}"/>

 

the rendered attribute will be evaulated when the client side HTML is generated and display / hide appropriately.

Sudhir_MeruSudhir_Meru

Cory,

 

  Thanks for your reply.  I am using HTML tag inside visual force. So its not allow me to add your code. Is there any alternative method ? Please suggest me.

 

Below is the HTML code inside visual force.  

 

 

<table class="tab1" width="100%" cellpadding="5" cellspacing="5" border="0">
  <tr>
       <td align="left">
         <img src='{!URLFOR($Resource.LogoMeru)}' title="logo" width = "150" height = "40"/>
       </td>
       <td class="tab1" valign="top" align="center" width="20%" style="background-color: #EEEEEE;"><h2>Distributor NSP</h2>
       </td>
   </tr>
   <tr class="tab1">
       <td style="font-size:8pt;">
         894 Ross Drive<br/>
         Sunnyvale, CA 94089<br/>
         Phone: 408-215-5300<br/>
         Fax: 408-215-5301    
       </td>   
        <td class="tab1" align="left" width="30%" style="background-color: #EEEEEE; font-size:8pt;">
       
             <strong>Opportunity Number&nbsp;:</strong> {!Opportunity.Id}<br/>
            
    
                        
             </td>   
             </tr>
</table>

 

 

Thanks
Sudhir

Deshraj KumawatDeshraj Kumawat

It is always better to use Visualforce tags instead of HTML tags as visualforce tags will show the standard force.com page behaviour.

 

Still if you want to use HTML tags, you can put your specific HTML code (that you want to display based on some condition) in <apex:outputPnale> tag and use the "rendered" attribute in outputPanel tag as Corry mentioned earlier.

 

Thanks and dont forget to give kudos and mar this post as solution if this post helps you.

 

Deshraj Kumawat