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

SelectList in PageBlockTable

I have a pageBlockTable which is used to display a list of Accounts.
I have a column with a selectList in each row of the table.

My problem is that on selecting a value from the Select list I am unable to get the correctly selected value onto the controller.
From the debug log it is evident that the default selected value from the last row in the table is what gets set in the variable in the controller.

How do I get over this and get the correct value onto the controller ?


<apex:column headerValue="Action" width="80px"> 
                             <apex:selectList id="AcctTable" required="true" size="1" value="{!selectedValue}" >
                             <apex:actionSupport event="onchange" action="{!SortTheList}"/ >
                             <apex:selectOptions value="{!Items}"> 
                               <apex:param value="{!selectedValue}"  name="id"/>    



Best Answer chosen by Admin (Salesforce Developers) 

You need to create a wrapper class to hold the Select Options and the selected value....


public class YOURCLASS{


sObject record = YOUR OBJECT

recWrapper[] wrapper {get;set;}


public void createWrapper(){

     wrapper = New recWrapper{}[];




public recWrapper{


sObject theRec = YOUR OBJECT {get;set;}

SelectOption[] theOptions {get;set;}

String SelectedValue {get;set;}


         public recWrapper(sObject rec){


            theRec = rec;

            //Populate the Select options list or pass it in






Then use the wrapper[] as your data source in the pageblocktable. Use the selectedValue for the select list and theOptions for the select Options. It will require you to use a custom save method to parse through the results. Obviously the code needs fine tuning to your situation but it is a start.