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
DTCFDTCF 

Setting the default value of a picklist in a datatable

I am trying to create a dynamic picklist in a datatable. The issue I'm having is that I need to set the default value of the picklist, and I need to be able to store the value of whatever it is changed to, which will 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:selectOption itemValue="" itemLabel=""/>
     <apex:selectOptions value="{!VendorList}"/>
     </apex:selectList> 
                
</apex:column> 

 

All that I'm trying to accomplish is to have the value in the picklist pre-set to whatever the value of "selected_vendor__c" is (which I set dynamically in the list that creates "i"). It doesn't seem to be reflecting this value in the dropdown list.

 

 

Furthermore, I'm hoping that it will also save the value to the List I have in the controller. I've only ever set the value of a picklist to a single variable.

 

Thanks!

Alok_NagarroAlok_Nagarro

Hi,

 

One thing you need to do that set the value (which u want to default) as the first value of list in controller.Remove from list like " --select--   or --None--" as first value.

I think it should work,in case of any failure let me know.

 

 

Thanks.

DTCFDTCF

Alok,

 

Thanks very much for the suggestion. I hadn't tried that before, but it still did not work. Do you have any other ideas?

 

Thanks,

David

paul-lmipaul-lmi

what's the controller code for this part look like?  you might just need to dynamically populate itemvalue in your page with a value.  do you wan the same default for every instance of the picklist?

DTCFDTCF
    
           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;
    }

 

I don't really quite understand how to set itemvalue dynamically. Basically, another object will have a text field that corresponds to one of the vendors listed in the vendor list, and it i needs to set it based on that.

 

Thanks so much!

paul-lmipaul-lmi

maybe this was more than I could fully grasp.  does your existing code work in respect to saving the changed value already, or are you starting with this task, and then moving on to that one?

DTCFDTCF

Exactly, I'm starting with this one. I just needed it to be able to set the value of a picklist dynamically within a larger datatable to whatever it is associated with the record in question. The picklist has to have all of the available and current vendors, but then needs to be set automatically to whatever the currently selected vendor is.

 

Thank you again!

 

DTCFDTCF

Anyone? I really need this capability. Any suggestions for work arounds?

DTCFDTCF

I think I solved this. I created an additional field on my object to store the value, and then I had to set it to the *id* of the item in the select list not the name. Seems obvious now.