Your Page Title
🔍

    Understanding apex:dataList Component in Visualforce

    The <apex:dataList> component is used to display items from a collection (like a list or set) using simple HTML tags like <ul>, <ol>, or custom tags. It’s a lightweight option for rendering lists compared to tables.


    Key Features

    • Binds directly to a list of data.
    • Repeats a block of markup for each item.
    • Flexible with any HTML structure.

    Syntax

    xmlCopyEdit<apex:dataList value="{!myList}" var="item" type="ul">
        <li>{!item}</li>
    </apex:dataList>
    
    • value: The list of items (from controller).
    • var: The variable representing each item.
    • type: The HTML tag to wrap the list (ul, ol, or custom).

    Example: Display a List of Courses

    xmlCopyEdit<apex:page controller="DataListDemo">
        <apex:form>
            <apex:dataList value="{!courses}" var="course" type="ul">
                <li>{!course}</li>
            </apex:dataList>
        </apex:form>
    </apex:page>
    

    Apex Controller:

    apexCopyEditpublic class DataListDemo {
        public List<String> getCourses() {
            return new List<String>{'Sales Cloud', 'Service Cloud', 'Marketing Cloud'};
        }
    }
    

    Use Cases

    • Bullet or numbered lists
    • Quick item previews
    • Simple menus or tags

    When to Use

    • Use <apex:dataList> for basic, linear lists.
    • For tabular data, prefer <apex:dataTable>.