views:

33

answers:

1

I am trying to create a dynamic picklist in a datatable. I can set the default value with a single picklist, but not when there are multiple ones. I also need to be able to store the value of whatever it is changed to on any row, which will hopefully be bound to some variable in a list.

To accomplish this I created a new field on the object I'm using (called Vendor), called "selected_vendor__c":

<apex:column headerValue="Vendor">

 <apex:selectList value="{!i.selected_vendor__c}" size="1" required="true" >
 <apex:selectOptions value="{!VendorList}"/>
 </apex:selectList> 

And then here is the controller:

           public List<selectOption> VendorList {get {
    List<selectOption> myVendorList = new List<selectOption>();
    for (Vendor__c vend : [select Name,id from Vendor__c])
        myVendorList.add(new selectOption(vend.id, vend.name));
    return myVendorList;
    }
    private set;
}

The problem I'm having is that the value in the picklist is always the first option from the list, not what I try to set it to dynamically. I'm hoping that it will be bound to "{!i.selected_vendor__c}" when saving, but I can't get it to be set to a default.

+1  A: 

I figured this out myself. The issue is that the value of i.selected_vendor__c needed to be the id corresponding to the vendor list, not the name.

dt

related questions