+ Start a Discussion
Nagaraju Mogili 31Nagaraju Mogili 31 

need to show the Account and its related contacts in single vf page using pageblock table

public class PageBlockTable_cntrlr {
   Public List<Account> acclist {get;set;}
   
   public PageBlockTable_cntrlr(){
     acclist = new List<Account>([select Id,Name,(select firstname,LastName from contacts) from Account]);
    }
}

======

<apex:page controller="PageBlockTable_cntrlr" >
<apex:form >
   <apex:pageBlock title="List OF Accounts">
      <apex:pageBlockTable value="{!acclist}" var="x">
          <apex:column value="{!x.Id}"/>
          <apex:column value="{!x.Name}"/><tr>
          <apex:pageBlockTable value="{!x.contacts}" var="y">
             <apex:column value="{!y.firstname}"/>
             <apex:column value="{!y.LastName}"/>
          </apex:pageBlockTable> </tr>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:form>   
</apex:page>
=============
with this I can able to display the single Account details only, how can i display the contact details beside of Account object
Avishek Nanda 14Avishek Nanda 14
Hi Nagaraju,
<table>
  <apex:repeat value="{!accs}" var="acc">
    <tr>
      <td><apex:outputText value="{!acc.Name}"/></td>
      <apex:repeat value="{!acc.Contacts}" var="cont">
         <td><apex:outputText value="{!cont.Name}"/></td>
      </apex:repeat>
    </tr>
  </apex:repeat>
</table>
This should help you.
Regards,
Avishek nanda

Mark this as your best answer if it resolves your query.
 
Brahmaiah GantaBrahmaiah Ganta
Hi,
try this once may be it should helps

<apex:page controller="PageBlockTable_cntrlr" >
<apex:form >
   <apex:pageBlock title="List OF Accounts">
      <apex:pageBlockTable value="{!acclist}" var="x">
          <apex:column value="{!x.Id}"/>
          <apex:column value="{!x.Name}"/>
          <apex:column headerValue="FirstName">
              <apex:repeat value="{!x.Contacts}" var="string" >
                  <apex:outputText value="{!string.FirstName}"/><br/>
              </apex:repeat>
          </apex:column>
          <apex:column headerValue="LastName">
              <apex:repeat value="{!x.Contacts}" var="string" >
                  <apex:outputText value="{!string.LastName}"/><br/>
              </apex:repeat>
          </apex:column>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:form>   
</apex:page>