+ Start a Discussion
chokchok 

need help in pageblock table to retrive data from database

Hi,

I am new to programming can any one help me please.i want to retrive data from database and display in VF pageblock table.

Best Answer chosen by Admin (Salesforce Developers) 
rajesh_yrajesh_y

this is code to get account data from database(back end) to vf page

 

controller :

public class classname

{

list<account>  alist=new list<account>();

public classname()

{

for(account a:[select name from account])

{

alist.add(a);

}

}

public list<account> getalist()

{

return alist;

}

}

page:

<apex:page controller="classname">

<apex:pageblock>

<apex:pageblocktable value="{!alist}" var="a">

<apex:column headervalue="name">

<apex:outputfield value="{!a.name}"/>

</apex:column>

</apex:pageblocktable>

</apex:pageblock>

</apex:page>

the code same for  all custom and standard objects using controller

All Answers

goabhigogoabhigo

Are you using controller/extension?

 

Here is the sample code:

 

<apex:pageBlockTable value="{!UrObj}" var="obj" columns="2" >
  <apex:column headerValue="ColumnHeading1" value="{!obj.Field1}" />
  <apex:column headerValue="ColumnHeading2" value="{!obj.Field2}" />
  ...
  ..
  .
</apex:pageBlockTable>

 

 

 

rajesh_yrajesh_y

this is code to get account data from database(back end) to vf page

 

controller :

public class classname

{

list<account>  alist=new list<account>();

public classname()

{

for(account a:[select name from account])

{

alist.add(a);

}

}

public list<account> getalist()

{

return alist;

}

}

page:

<apex:page controller="classname">

<apex:pageblock>

<apex:pageblocktable value="{!alist}" var="a">

<apex:column headervalue="name">

<apex:outputfield value="{!a.name}"/>

</apex:column>

</apex:pageblocktable>

</apex:pageblock>

</apex:page>

the code same for  all custom and standard objects using controller

This was selected as the best answer
chokchok

Thanks for your help,i will try it and keep you update.I am using custom controller.my task is use to display yearly salary according to job title in VF PAGE BLOCK table.