+ Start a Discussion
DDharDDhar 

Multi select pick list on visual Force page

Hi,

 

Could anyone tell me how can i get multi select pick list on visual force page with custom controller. I was trying the same with newly custom object and then using that as custom controller and things were fine but now i want to have a) visual force page b) custom controller and c) data (picklist data) pulled from custom object.

 

 

Thanks,

Dilip

PremanathPremanath

Hi try this code

 

 

<apex:page controller="test1">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Data}" var="acc">
<apex:column value="{!acc.Name}"/>
<apex:column value="{!acc.Pickval__c}"/>
</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>

</apex:page>

 

 

public class test1 {

List<Tasks__c> Varacc;

public List<Tasks__c> getData()
{
Varacc =[Select id,Name,Pickval__c from Tasks__c];
if(varacc.size()>0)
{
return Varacc;
}
return null;
}
}

 

 

 

 

here Task__c is custom obj,  Pickval__c is multi-picklist

 

 

 

 

 

if it is helpful plz make it as solution for others it may benfit

 

Prem

rebvijkumrebvijkum

    String[] reasons = new String[]{};
    
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Broken Link','Broken Link'));
        options.add(new SelectOption('Page Unclear','Page Unclear'));
        options.add(new SelectOption('Missing Information','Missing Information'));
        options.add(new SelectOption('Hard to Find Page','Hard to Find Page'));
        options.add(new SelectOption('Other','Other'));
        return options;
    }

    public String[] getReasons() {
        return reasons;
    }
            
    public void setreasons(String[] reasons) {
        this.reasons = reasons;
    }     
    public PageReference saveclick() {
      
        ArticleFeedbackObj.Reason__c = '';
        if(reasons != null && !reasons.isEmpty()) {
            for(Integer i=0; i < reasons.size(); i++) {
                ArticleFeedbackObj.Reason__c = ArticleFeedbackObj.Reason__c+';'+reasons[i];
            }
        }
           return null;
    }   
 
Chanagan SakulteeraChanagan Sakulteera
This is get data form picklist to select list.
This is code in controller

    public List<SelectOption> getMyType(){ 
        List<SelectOption> lstType = new List<SelectOption>();      
    
        // Reading picklist values and labels
        Schema.DescribeFieldResult fieldResult = Services__c.Service_Type__c.getDescribe();
        List<Schema.PicklistEntry> picklistEntries = fieldResult.getPicklistValues();

        // Adding apicklist values to the select list
        for(Schema.PicklistEntry entry : picklistEntries){
            lstType.add(new SelectOption(entry.getValue(), entry.getLabel())); 
        }
    
        return lstType;
    }

This is code in vf page.
Service Type 
                <apex:selectList value="{!type}" size="1" multiselect="false">
                    <apex:selectOption itemValue="" itemlabel="==Not Specify=="></apex:selectOption>
                    <apex:selectOptions value="{!MyType}"/>
                </apex:selectList>

You try to use. Hope this help.