+ Start a Discussion
Naresh K 12Naresh K 12 

Displaying Question and Answers in Pagination

Hello Team,

I want to display  few questions  and answers realted to that questions in Visual force page. But on click of next question, i have to get second and so on 

Would you please guide me how to achieve this, I tried using pagination but facing difficulties to retrieve answer options.

These question and answers are stored in same table.

Thanks,
Kumar
Ankit Gupta@ DeveloperAnkit Gupta@ Developer
Hi Naresh,

You can use the standard controller pagination

Usethe below code sample as reference:

Visualforce Page
<apex:page controller="DisplayHolidayCls">
    <apex:form >
        <style>
body .pbBody table.list tr.dataRow.highlight td {
    background-color: #fff !important;
}
        </style>
        <apex:pageBlock title="Holidays View">
            
            <apex:pageBlockTable value="{!lstContact}" rowClasses="oddrow,evenrow" var="objCon">
                <apex:column headerValue="Account" value="{!objCon.Account.Name}"> </apex:column>
                <apex:column value="{!objCon.Name}" />
                <apex:column colspan="2" breakBefore="true">
                    <Apex:outputPanel >
                        <div class="listRelatedObject taskBlock">
                            <div class="bPageBlock brandSecondaryBrd secondaryPalette">
                                <div class="pbHeader">
                                    <table border="0" cellpadding="0" cellspacing="0">
                                        <tbody>
                                            <tr>
                                                <td class="pbTitle">
                                                    <h3 id="Tableheading">Holidays</h3></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <apex:outputPanel rendered="{!objCon.Holidays__r.size<=0}">
                                    <div class="pbBody" id="RelatedHolidays">
                                        <table class="list" border="0" cellspacing="0" cellpadding="0">
                                            <tbody>
                                                <tr class="headerRow">
                                                    <th scope="col" class="noRowsHeader">No records to display</th>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </apex:outputPanel>
                                <apex:outputPanel rendered="{!objCon.Holidays__r.size>0}">
                                    <Apex:pageBlockTable value="{!objCon.Holidays__r}" var="objHoliday">
                                        <Apex:column headervalue="Name"> <a href="/{!objHoliday.id}">{!objHoliday.name}</a> </Apex:column>
                                    </Apex:pageBlockTable>
                                </Apex:outputPanel>
                            </div>
                        </div>
                    </Apex:outputPanel>
                </apex:column>
            </apex:pageBlockTable>
            <apex:panelGrid columns="4">
                <apex:commandButton title="First" value="|<" action="{!first}" disabled="{!!hasPrevious}" />
                <apex:commandButton title="Previous" value="<<" action="{!previous}" disabled="{!!hasPrevious}" />
                <apex:commandButton title="Next" value=">>" action="{!next}" disabled="{!!hasNext}" />
                <apex:commandButton title="Last" value=">|" action="{!last}" /> </apex:panelGrid>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex class
 
public class DisplayHolidayCls
{
    public ApexPages.StandardSetController con{get; set;}
    public DisplayHolidayCls()
    {
        getData();
    }
    public list < contact > lstContact
    {
        get
        {
            if (con != null) return (List < contact > ) con.getRecords();
            else return null;
        }
        set;
    }
    public void getData()
        {
            con = new ApexPages.StandardSetController(Database.getQueryLocator([select id, name, accountid, account.name, (select id, name from Holidays__r) from contact limit 50000]));
            con.setPageSize(10);
        }
        //Boolean to check if there are more records after the present displaying records
    public Boolean hasNext
    {
        get
        {
            return con.getHasNext();
        }
        set;
    }
    //Boolean to check if there are more records before the present displaying records
    public Boolean hasPrevious
    {
        get
        {
            return con.getHasPrevious();
        }
        set;
    }
    public Integer pageNumber
    {
        get
        {
            return con.getPageNumber();
        }
        set;
    }
    public void first()
    {
        con.first();
    }
    public void last()
    {
        con.last();
    }
    public void previous()
    {
        con.previous();
    }
    public void next()
    {
        con.next();
    }
}


Regards
Ankit Gupta