[SalesForce] Display repeat data in a table

I got the following apex class and the Visualforce page. I want to display the repeat data in a apex:pageblockTable. How can I put this as a column in the table? Currently records are displaying outside the pageblock.

public with sharing class BusinessUnitMember{

public List<grc__Business_Unit__c> theBusinessUnit {get; set;}
public List<User> selectionUsers {get; set;}

public BusinessUnitMember(ApexPages.StandardController con)
    {

       theBusinessUnit = [select Id, Name, OwnerId, Sharing_Group_Name__c, Read_Write_Access_to_Child_BUs__c
                           from grc__Business_Unit__c 
                           order by Name
                           limit 50000
                           ];
}
}

VF page

<apex:page standardController="grc__Business_Unit__c" extensions="BusinessUnitMember" standardStylesheets="true">
<apex:form id="form">
<apex:pageBlock title="Business Unit Member"/>
<apex:repeat value="{!theBusinessUnit}" var="dbItem">
<apex:outputText value="{!dbItem.Name}" /><br/>
</apex:repeat>
</apex:form> 
</apex:page>

Best Answer

The apex:pageBlockTable tag, like the apex:repeat tag, is an iterating tag that also takes a value and a var attribute. More here: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_pageBlockTable.htm

If you swap out your repeat for the pageBlockTable, you would get something like:

<apex:page standardController="grc__Business_Unit__c" extensions="BusinessUnitMember" standardStylesheets="true">
<apex:form id="form">
<apex:pageBlock title="Business Unit Member"/>
<apex:pageBlockTable value="{!theBusinessUnit}" var="dbItem">
    <apex:column value="{!dbItem.Name}" />
    <apex:column value="{!dbItem.Sharing_Group_Name__c}" />
</apex:pageBlockTable>
</apex:form> 
</apex:page>

For an excellent blog on how the various VF tags work, check out Steven Herod's blog at: http://limitexception.com/2014/03/30/visualforce-a-visual-reference-guide/

Related Topic