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
mukesh guptamukesh gupta 

selectList does not display content

Hi Expert, 

I am creating a dropdown list by VF and apex page. but i am not getting the value from drop down, it's display blank.
 
<apex:pageBlockSectionItem >
         <apex:outputLabel value="Card Type"></apex:outputLabel>
                   <apex:selectList value="{!selectedCardType}">
                   <apex:selectOptions value="{!cardTypes}" />
            </apex:selectList>
</apex:pageBlockSectionItem>



///////////////////-------------------------------------------////////////////////////////

public String cardTypes { get; set; }
 public String selectedCardType { get; set; }

 public List<SelectOption> getCardTypes(){
       list<SelectOption> cardtype = new list<SelectOption>();
       cardtype.add(new selectOption('Visa','Visa'));
       cardtype.add(new selectOption('Master Card','Master Card'));
       cardtype.add(new selectOption('American Express','American Express'));
       return cardtype;
    }

Please suggest 
Thanks
Mukesh
 
 
Best Answer chosen by mukesh gupta
Akshay_DhimanAkshay_Dhiman
Hi Mukesh ,

There were very small mistakes in your , I have done some modification in the code.

Try the code below,

Visualforce Page :
 
<apex:page controller="displaySelectionlistController" >
    
    <apex:pageBlock>
        <apex:pageBlockSection>
    <apex:pageBlockSectionItem>
        <apex:form>
        <apex:outputLabel value="Card Type"></apex:outputLabel>
        
        <apex:selectList  size="1" value="{!selectedCardType}">
            <apex:selectOptions value="{!cardtype}" />
        </apex:selectList>
            </apex:form>
    </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Controller (Apex class):
 
public class displaySelectionlistController
{
    public list<SelectOption> cardtype {get; set;}
    public String selectedCardType {get;set;}
    public displaySelectionlistController ()
    {
     
        selectedCardType = Null;
        cardtype = new list<SelectOption>();
        cardtype.add(new selectOption('Value1','Value1'));
        cardtype.add(new selectOption('Value2','Value2'));
        cardtype.add(new selectOption('Value3','Value3'));
        /* By this Way you can Enter N number of Values in the SelectOption list*/
    }
}


Regards ,
Akshay
Please mark my answer as a solution if it was helpful.

All Answers

Harshit Garg 6Harshit Garg 6
Hi Mukesh,

Apex class:
String[] CardTypes = new String[]{};

 public PageReference test() {
        return null;
    }
 
 public List<SelectOption> getitems(){
       list<SelectOption> options  = new list<SelectOption>();
       options.add(new selectOption('Visa','Visa'));
       options.add(new selectOption('Master Card','Master Card'));
       options.add(new selectOption('American Express','American Express'));
       return options ;
    }
	
	public String[] getCardTypes() {
        return CardTypes;
    }
	
	public void setCardTypes(String[] CardTypes) {
        this.CardTypes = CardTypes;
    }
Vf page:
<apex:form >
        <apex:selectList value="{!CardTypes}" size="1" multiselect="true">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList><p/>

        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
    </apex:form>

    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    <p>You have selected:</p>
                    <apex:dataList value="{!CardTypes}" var="c">{!c}</apex:dataList>
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
</apex:page>

Thanks,
Harshit Garg


 
Harshit Garg 6Harshit Garg 6
HI,
 
<apex:selectList value="{!selectedCardType}" size="1" multiselect="true">
You can use that in your vfpage.It will work for you.

Thanks,
Harshit garg
 
Akshay_DhimanAkshay_Dhiman
Hi Mukesh ,

There were very small mistakes in your , I have done some modification in the code.

Try the code below,

Visualforce Page :
 
<apex:page controller="displaySelectionlistController" >
    
    <apex:pageBlock>
        <apex:pageBlockSection>
    <apex:pageBlockSectionItem>
        <apex:form>
        <apex:outputLabel value="Card Type"></apex:outputLabel>
        
        <apex:selectList  size="1" value="{!selectedCardType}">
            <apex:selectOptions value="{!cardtype}" />
        </apex:selectList>
            </apex:form>
    </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Controller (Apex class):
 
public class displaySelectionlistController
{
    public list<SelectOption> cardtype {get; set;}
    public String selectedCardType {get;set;}
    public displaySelectionlistController ()
    {
     
        selectedCardType = Null;
        cardtype = new list<SelectOption>();
        cardtype.add(new selectOption('Value1','Value1'));
        cardtype.add(new selectOption('Value2','Value2'));
        cardtype.add(new selectOption('Value3','Value3'));
        /* By this Way you can Enter N number of Values in the SelectOption list*/
    }
}


Regards ,
Akshay
Please mark my answer as a solution if it was helpful.
This was selected as the best answer