+ Start a Discussion
URVASHIURVASHI 

passing default value in select list through constructor after sorting the select list

hello,

Can anyone help

I m new to Salesforce please help.

I have a picklist with some values of fruits in it.

Example:

Apple Grapes Banana etc.

I have sorted these values alphabetically.

But now i want a default value to be added in picklist like example: '--Select value--'

Can i pass this value directly to the constructor to make it default to picklist?

Or should I add it first to the select list.

 

Please help

Thanks.

 

Best Answer chosen by Admin (Salesforce Developers) 
Neha LundNeha Lund

Hey just try this...

list<SelectOption> updatedList=new List<SelectOption>();

updatedList.add('---<Select None>---');

updatedList.addAll(**Put the Sorted list here****);

use the updated List in your Vf page...

All Answers

Sonali BhardwajSonali Bhardwaj
you need to add it to select list, like you added other fruit values. And variable which is binded to select list, you need to assign "--Select value--" Id value, which you might keep blank string - ''.
Neha LundNeha Lund

Hey just try this...

list<SelectOption> updatedList=new List<SelectOption>();

updatedList.add('---<Select None>---');

updatedList.addAll(**Put the Sorted list here****);

use the updated List in your Vf page...

This was selected as the best answer