+ Start a Discussion
sp13sp13 

save the value selected in selectOptions

 

i was able to display values to the picklist using this code:

VF PAGE:
<apex:column headerValue="Year/Block">
    <apex:selectList size="1" value="{!course.Year_Block__c}">
        <apex:selectOptions value="{!statusOptions}"/>
    </apex:selectList>
</apex:column>
Apex Class: public Student__c student {get;set;} public Course__c course {get;set;} public List<StudentWrapper> wrappers {get; set;} public List<CourseWrapper> wrapperc {get;set;} public List<SelectOption> statusOptions {get;set;} public NewStudentEntryCX(ApexPages.StandardController controller) { //other codes statusOptions = new List<SelectOption>(); Schema.DescribeFieldResult statusFieldDescription = Course__c.Year_Block__c.getDescribe(); Course__c var = [Select Id, Year_Block__c from Course__c where Id = : Apexpages.currentPage().getParameters().get('id')]; for(String s: var.Year_block__c.split(';')) statusOptions.add(new SelectOption(s, s)); } public PageReference save() { List<Student__c> studentList = new List<Student__c>(); for (StudentWrapper wrap : wrappers) { Student__c student = new Student__c(); student.Full_Name__c = wrap.studentwrap.Full_Name__c; student.Email__c = wrap.studentwrap.Email__c ; student.Gender__c = wrap.studentwrap.Gender__c ; student.Course__c = getCourseList().id;
student.Year_Block__c = **-should be the selectOption value-** studentList.add(student); } insert studentList; PageReference p = new PageReference('/apex/Main'); return p; }

 my problem is how can i get the value of the picklist/selectOptions to save?

help please.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ericmonteericmonte

So in your Page for the selectList Value use a variable where you set the Options value.

 

<apex:selectList value="{!strVar}" size="1">
                         <apex:outputText >Quarter: </apex:outputText>
                         <apex:selectOptions value="{!statusOptions}"/>
                    </apex:selectList>

 

In your class you can do:

 

Public string strVar{get;set;}

 

 

and then do this:

student.Year_Block__c = strVar

 

 

See if this make sense.