0

How i can use if else like statement in vf page inside repeat component. My code is

<apex:repeat value="{!strings}" var="string" id="theRepeat" >


            <apex:outputPanel >
                    <div class="tParent" style="padding-top:15px;">
                        <div class="tBox_left">
                            <div class="boxTip"></div>
                            <div class="midPoint"><p>10/22</p></div>
                            <h3>RFQ: Hallmark</h3>
                            <div class="dropFile"></div>

                        </div>
                    </div>
                </apex:outputPanel>

              <apex:outputPanel >

                    <div class="tParent marTop">
                        <div class="tBox_right">
                            <div class="boxTip_right"></div>
                            <div class="midPoint_right"><p>10/23</p></div>
                            <h3>Kimball</h3>
                            <div class="dropFile"></div>
                              <h4 class="boxMail">
                          </div>
                     </div>
               </apex:outputPanel>
            </apex:repeat>

In this code inside repeat component i am using two outputpanel comp.Whenever loop is executed i don't want to display both outputpanel for every loop alternative outputpanel should execute like..

<apex:repeat value="{!strings}" var="string" id="theRepeat" >
     <apex:outputPanel  if()>
     {
          print this
     }
else
     <apex:outputPanel  >
     {
          print this
     }

Main reason for this is whenever loop run 1st time it should display data on left side and second time when it run the loop it should display data on right side so on.....

1 Answer 1

4

You can do this using an apex:variable in your page. Sample follows:

<apex:page standardController="Account" recordSetVar="Accounts">
    <apex:variable value="{!0}" var="counter"/>
    <table><tbody>
    <apex:repeat value="{!accounts}" var="record">
        <apex:outputPanel rendered="{!mod(counter,2)=0}">
            <apex:outputText escape="false" value="<tr>"/>
                <td>{!record.name}</td>
        </apex:outputPanel>
        <apex:outputPanel rendered="{!mod(counter,2)=1}">
                <td>{!record.name}</td>
            <apex:outputText escape="false" value="</tr>"/>
        </apex:outputPanel>
        <apex:variable value="{!counter+1}" var="counter"/>
    </apex:repeat>
    </tbody></table>
</apex:page>
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .