+ Start a Discussion
raju123raju123 

How to Hide/show a pageBlock depending upon the button selection?

 

hi,

Please check bellow code in which 2 pageblock sections are there. initially only 1st block we can see. if we click on yes second bolck will apear.

but

My Problem when we click on yes second needs to appear and first block needs to Hide.
Please Can any one help me out
public class Wizard_3a_Controller
{

Boolean testval = false;
public pagereference showSection1() {
setHideshow(true);
return null; }

public pagereference ShowSection2()
{
setHideshow(false);
return null;
}

public Boolean getHideshow()
{
return this.testval;
}
public void setHideshow(boolean s)
{
this.testval = s;
}
}

and
Code:
<apex:page controller="Wizard_3a_Controller">
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection title='Rate Information'>
Are there proposed non-standard electronic rates—<br/>
<apex:commandButton action="{!showSection1}" value='Yes' styleClass='btn' rerender='details'></apex:commandButton>
<apex:commandButton action="{!showSection2}" value='No' styleClass='btn'></apex:commandButton>
</apex:pageBlockSection>
<apex:outputPanel id='details'>
<apex:pageBlockSection id ='newData' title='Discount Rates' rendered='{!hideshow}'>
Enter Proposal range
</apex:pageBlockSection>

</apex:outputPanel>

</apex:pageBlock>
</apex:form>
</apex:page>

vishal@forcevishal@force

Change your VF code to this:

 

<apex:page controller="Wizard_3a_Controller">
<apex:form >
<apex:pageBlock >
<apex:outputPanel id="details">
<apex:pageBlockSection title="Rate Information" rendered="{!!hideShow}"> 
Are there proposed non-standard electronic rates—<br/>
<apex:commandButton action="{!showSection1}" value="Yes" styleClass="btn" rerender="details"></apex:commandButton>
<apex:commandButton action="{!showSection2}" value="No" styleClass="btn" rerender="details"></apex:commandButton>
</apex:pageBlockSection>

<apex:pageBlockSection id="newData" title="Discount Rates" rendered="{!hideshow}">
Enter Proposal range
</apex:pageBlockSection>

</apex:outputPanel>

</apex:pageBlock>
</apex:form>
</apex:page>

 This will hide the first section when you click "Yes". Hope it helps :)