You need to sign in to do that
Don't have an account?
bpl3792
Need help building a list populated by soql statement
I'm trying to populate a list from a soql statment. It's currently populating 1 item but I'm not sure where the loop should go.
<apex:selectList id="Modelbox" value="{!Models}" size="1" title="Type" onchange="searchServer(this.options[this.selectedIndex].text)"> <apex:selectOptions value="{!items}"></apex:selectOptions> </apex:selectList>
Here's the controller
//Variables String[] models = new String[]{}; //sobject public IT_Asset__c ITA {get;set;} public AssetManController() { ITA=[SELECT Workstation_Model__c FROM IT_Asset__c]; } public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); for(integer i=0;i<30;i++) { options.add(new SelectOption(ITA.Workstation_Model__c,ITA.Workstation_Model__c)); } return options; } public string[] getModels() { return models; } public void setModels(string[] models) { this.models=models; }
This should help
All Answers
This should help
Still only displaying 1 record. It's strange because the record it's displaying isn't the first record or the last...it's like 1/4 through.
This works for me
and in the controller
I think its the same apart from the onchange in your VF
Your code works exactly the way it supposed to. The failure was on my end. I've just started playing with visualforce and apex so my understanding is a little off. I thought my code actually pulled data down from the "Workstation_Model__c" object. After talking to one of our salesforce devs I found out that all I needed to do is call the standard controller for that object. So after all that all I needed to do was <apex:inputfield value="{!IT_Asset__c.Workstation_Model__c}"/>
Thanks for the help!
If Workstation Model is a picklist field then <apex : inputfield ... is exactly what you should use.
What you were trying to do would only display the values that had been stored in the IT Asset records.