[SalesForce] How to display data on custom visual force page on page load

I'm a relative newbie so please be gentle…

I've created a visualforce page using a custom controller. The VF page contains a number of fields and a drop down list (i.e. Industry) from which users can search for data. I would like the VF page to display 'All Industries' on page load. However, I can't get this to work.

My constructor snippet is as follows:

public MyController(){
    AccountList = new list<AccountSubClass>();
    AccountSelectedSet = new set<Id>();

    Industry = ApexPages.currentPage().getParameters().get('All Industries');

    BuildQuery();  
}

Grateful for any assistance. Happy to provide more details if it helps…

Best Answer

You have a couple of options here, you can either build your drop-down list in your Visualforce page or you can build it in apex. To do it in Visualforce, you just need VF markup that looks something like this:

<apex:selectlist value="{!selectedndustry}" size="1">
     <apex:selectOption itemValue="all" itemLabel="All Industries"/>
 </apex:selectlist>

And the apex for that would look something like this:

 public string selectedIndustry { get; set; }

Alternatively, you can build your list of SelectOptions in apex and repeat over them on the page. The apex for that would look like this:

<apex:selectlist value="{!selectedIndustry}" size="1">
     <apex:selectOptions value="{!industries}" />
</apex:selectlist>

And the apex for that would look something like this:

public string selectedIndustry { get; set; }
public list<SelectOption> getIndustries (){
     list<SelectOption> options = new list<SelectOption>();
     options.add(new SelectOption('all','All Industries'));
     //repeat
     return options;
}
Related Topic