+ Start a Discussion
chanti kchanti k 

How to display the table as a vertical in visual force page.

Hi All,

i want display the table as a vertical in visualforce page. pls demonstration this how to we can achive this.Give me example code 

Thanks,
Chanti
CloudGeekCloudGeek
Hello Chanti,

Here is an example for building a table in visualforce:
 
<apex:page standardController="Account">
   <apex:pageBlock title="Hello {!$User.FirstName}!">
      You are viewing the {!account.name} account.
   </apex:pageBlock>
   <apex:pageBlock title="Contacts">
      <apex:pageBlockTable value="{!account.Contacts}" var="contact">
         <apex:column value="{!contact.Name}"/>
         <apex:column value="{!contact.MailingCity}"/>
         <apex:column value="{!contact.Phone}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

If you want to use Custom Controller try as shown below:
//Example APEX CLASS 
public class opportunityList2Con {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Name, CloseDate FROM Opportunity]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records
    public List<Opportunity> getOpportunities() {
        return (List<Opportunity>) setCon.getRecords();
    }
}


//The following Visualforce markup shows how the custom controller above can be used //in a page:

<apex:page controller="opportunityList2Con">
    <apex:pageBlock>
        <apex:pageBlockTable value="{!opportunities}" var="o">
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.CloseDate}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Note: Please mark this as best answer if this help you resolve.
Akshay_DhimanAkshay_Dhiman
you can show the record via two ways:-
     1. By using Salesforce Record
     2. By using Manual Record
In below example I am using Account record in Salesforce,

Custom Controller as shown below :
public class shows20recordsapex {
    public List<Account> AccList
    {
        get;
        set;
    }
    public shows20recordsapex() {
        AccList = [Select id,Name,Phone from Account limit 20];
    }
}
Visualforce Page as shown below :
<apex:page controller="shows20recordsapex">
    <apex:form>
        <apex:pageBlock title="20 Records of Accounts">
                <table border="2px">
                    <tr>
                        <th>Id</th>
                        <th>Name</th>
                        <th>Phone</th>
                    </tr>
            <apex:repeat value="{!accList}" var="a" >
                    <tr>
                        <td>{! a.Id}</td> 
                        <td>{! a.Name}</td>
                        <td>{! a.phone}</td>
                    </tr>
            </apex:repeat>
                    </table>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Hope it helps you.
 
 Regards,
 Akshay