Play Games

Search This Blog

Wednesday, October 23, 2019

Display first 5 elements of a list in visualforce page - Salesforce Globe For You

Display first 5 elements of a list in visualforce page

We can display first specified number of elements using rows attribute of <apex:repeat> tag.

Apex Code: DisplayFirst5Element

public class DisplayFirst5Element {
    public List<Integer> lstNumber {get;set;}
    public DisplayFirst5Element() {
        lstNumber = new List<Integer>();
        for(integer i=1; i<20; i++) {
            lstNumber.add(i);
        }
    }
}

Visualforce Page: DisplayFirst5Element

<apex:page controller="DisplayFirst5Element" id="thePage">
    <b>First 5 Elements are:</b><br/>
    <apex:repeat value="{!lstNumber}" var="num" id="theRepeat" rows="5">
        <apex:outputText value="{!num}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>

Output:

No comments:

Post a Comment