Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Selectoptions used in SelectCheckboxes shows the checkboxes in a single Row. I need to show the checkboxes in different rows. Ho can this be acheived.

My code is :

<!-- Page: -->
<apex:page controller="sampleCon">

    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection columns="2">
               <tr>
                <apex:selectCheckboxes borderVisible="true" value="{!countries}" styleClass="check">
                       <apex:selectOptions value="{!items}" />
                </apex:selectCheckboxes>
                </tr>
                <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
 </apex:page>

My Controller is : ** Controller: **

public class sampleCon {

    public List<SelectOption> items{get;set;}
    public List<String> countries {get;set;}

    public PageReference test() {
        return null;
    }

    public sampleCon(){
        getItems();
    }

    public void getItems() {

        items= new List<SelectOption>();
        countries = new List<String>();
        /*
        options.add(new SelectOption('US','US'));
        options.add(new SelectOption('CANADA','Canada'));
        options.add(new SelectOption('MEXICO','Mexico'));
        */
        Schema.DescribeFieldResult F = Case.Numbers__c.getDescribe();
        List<Schema.PicklistEntry> P = F.getPicklistValues();
        System.debug(P);
        for (Schema.PicklistEntry a : P)
          { 
             items.add(new SelectOption(a.getLabel(), a.getValue())); 
          }

    }

         public List<String> getCountries() {
            return countries;
         }

         public void setCountries(List<String> countries) {
             this.countries = countries;
         }

    }

The output I get is :

snapshot

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Use layout="pageDirection" in selectCheckboxes for ex.

<apex:form >
<apex:pageBlock >
    <apex:pageBlockSection columns="2">
       <tr>
        <apex:selectCheckboxes borderVisible="true" value="{!countries}" styleClass="check" layout="pageDirection">
               <apex:selectOptions value="{!items}" />
        </apex:selectCheckboxes>
        </tr>
        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
    </apex:pageBlockSection>
</apex:pageBlock>

share|improve this answer
2  
Or in your 'check' class add "display: block;" –  Bachovski Jul 17 at 4:45
    
Thanks.It worked. Any Idea how to show the checkboxes in two columns. –  Bhoopesh Chauhan Jul 17 at 4:51
1  
For two columns you will need to use CSS. something like display:inline-block –  AtulRajguru9 Jul 17 at 5:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.