Find your content:

Search form

You are here

How to make the check box true even if it is not ticked in visual force page

 
Share

How to make the check box true even if it is not ticked in visual force page, I mean the picture with tick mark.

but its not working, is ther any other way

Edit:

<apex:page controller="controller">
<apex:form>
    <apex:pageBlock>
        <apex:pageBlockButtons>
            <apex:commandButton value="New " /></apex:pageBlockButtons>
        <apex:pageBlockTable value="{!Records}" var="R">
            <apex:column headerValue=" Name" value="{!R.name}" />
            <apex:column headerValue="City" value="{!R.City__c}" />
            <apex:column headerValue="Country" value="{!R.Country__c }" />
            <apex:column headerValue="CheckBox" value="{!R.checkbox__c}" />
       </apex:pageBlockTable>...

and

[class: public with sharing class controller {
      public list < Bank__c > objB = [select id, name, city__c, country__c, CheckBox__c from Bank__c];
       public list < bank__c > getRecords() {
           return objB;
       }
}]

Attribution to: rakesh

Possible Suggestion/Solution #1

The path to the pictures is

/img/checkbox_checked.gif
/img/checkbox_unchecked.gif

So you can easily use them in

...
<apex:column headerValue="CheckBox">
    <img src="/img/checkbox_checked.gif" />
    <!-- or maybe <apex:image value="/img/checkbox_{!IF(someCondition,'checked', 'unchecked')}.gif" /> -->
</apex:column>
...

You'll have trouble whenever Salesforce decides to move/rename them though. There are several similar questions here already (like Is there a list of Salesforce images that can be used in custom pages and formula fields?) that recommend downloading them, packing them up in your own static resource etc.

So "Safe Harbor" and good luck :)


EDIT: I think what you need is to tick all the checkboxes server-side? Something like this then:

public with sharing class controller {
    public list < Bank__c > objB = [select id, name, city__c, country__c, CheckBox__c from Bank__c];
    public list < bank__c > getRecords() {
        if(objB != null){
            for(Bank__c bank : objB){
                bank.CheckBox__c = true;
            }
        }
        return objB;
    }
}

Attribution to: eyescream

Possible Suggestion/Solution #2

Looking at the code looks like a a data issue.Please see the records through query at backend in eclipse or developer console to see if all records have CheckBox__c is true.


Attribution to: Mohith Shrivastava

Possible Suggestion/Solution #3

If you need all the checkboxes selected, I would follow eyescreams solution of iterating through the results in the controller and setting Checkbox__c to true:

public with sharing class controller(){
  //change set to public if you want to modify the records in your vf page..
  public List<Bank__c> records {get; private set;}

  public controller(){
    records = 
      [Select 
         Name, 
         City_c, 
         Country_c, 
         Checkbox_c 
       From 
         Bank_c];

    for(Bank__c record : records){
      record.Checkbox__c = true;
    }
  }
}

Also, depending on how you want the checkbox displayed, you can use a nested apex:inputField element, you can use the value attribute of the column (which your code is currently using), or you can use an apex:outputField to show the checkbox. Code for the latter is below:

<apex:pageBlockTable value="{!records}" var="record">
  <apex:column value="{!record.name}" />
  <apex:column value="{!record.City__c}" />
  <apex:column value="{!record.Country__c }" />
  <apex:column headerValue="{!$ObjectType.Bank__c.fields.Checkbox__c.label}">
    <apex:outputField value="{!record.Checkbox__c}" />
  </apex:column>
</apex:pageBlockTable>

Attribution to: James Loghry
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4393

My Block Status

My Block Content