I want to display the child records in a pageblock table when the parent id is selected.
I am generating the list of Account record on a page load and displayed the account records in a datatable and on click of the Account record i want to display the Child records in the same page, in that retrieved contact record want to edit some fields.Please suggest me the solution.
Thanks in Advance
Visualforce Page:
<apex:page controller="SignupformController">
<apex:form><apex:pageBlock title="Accounts">
<apex:dataTable value="{!accountlist}" var="a" cellPadding="4" border="1">
<apex:column >
<apex:commandLink onclick="{!contactdetails}" >
{!a.Name}
</apex:commandLink>
</apex:column>
</apex:dataTable>
<apex:dataTable value="{!contactdetails}" var="c" id="conid" cellPadding="4" border="1">
<apex:column >
{!c.Name}
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form> </apex:page>
Controller :
public with sharing class SignupformController{
public List<account> accountlist{get;set;}
public set<Id> accountids= new set<Id>();
public List<contact> contactlist{get;set;}
public string eventid{get;set;}
public SignupformController(){
accountlist= [select Id,Name FROM Account];
for(Account a : accountlist){accountids.add(a.Id)}
}
public void getcontactdetails(){
contactlist= [select Id,AccountId,Name From contact WHERE AccountId In:accountids];}
}