function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lovel PanchalLovel Panchal 

How to make checkboxs selected from apex code

I want that when I am binding by checkboxs at that time only based on condition I can make checkbox by default selected or unslected.

So how can I achieve that 

here's my apex code

public List<SelectOption> getChkboxItems() {
        List<SelectOption> options = new List<SelectOption>();           
        for(lovel__Item__c i: getitms()){
            boolean x =false;
            for(lovel__Item_Manufacture_Mapper__c imm: [SELECT lovel__Item__c FROM lovel__Item_Manufacture_Mapper__c WHERE lovel__Manufacturer__c = :id]){
                if(i.Id == imm.lovel__Item__c) {
                    x=true;
                }                 
            }
            options.add(new SelectOption(i.Id,i.Name,x));
        }
        return options;
    }
mritzimritzi
Add a boolean variable in Apex
 
public Boolean variable{get;set;}

//set it to true (checked) or flase (unchecked)
// variable =true;
// variable= false;

In VF Page, set the value as follows:
<apex:form>
    <apex:inputCheckBox selected="{!variable}"/> Sample Checkbox<br/>
</apex:form>

Accordingly, the checkbox would appear selected or un selected.



Hit LIKE, it this helps. Select it as Best Answer if it solves your problem.