+ Start a Discussion
URVASHIURVASHI 

Visualforce drop down list

Hi,

I am new to Salesforce.

Can anyone please help.

 

Below is my VF code:

  <apex:repeat value="{!InnerList}" var="in">
  
          <apex:selectList value="{!in.selectedValue1}" multiselect="false" style="width:200px;" size="1">
        
              <apex:selectOptions value="{!Header}"/>
             
               </apex:selectList>
            
          
          <apex:selectList value="{!in.selectedValue2}" multiselect="false" style="width:200px;" size="1">
               <apex:selectOptions value="{!FieldList}"/>
           
          </apex:selectList>
        
          
          
      </apex:repeat>

 Controller:

 

public class communityCon1234
{

    public list<communityCon1Inner> Innerlist{get;set;}
    
    public class communityCon1Inner
    {
         public string selectedValue1{get;set;}
         public String selectedValue2{set;get;}
           
    }
     public communityCon1234()
    {
       InnerList = new list<communityCon1Inner>();  
       
        
       communityCon1Inner c= new communityCon1Inner();
       
         InnerList.add(c);
     }
}

 And FieldList and Header contains values of drop down.

 Suppose Header contains values like:

 Name

 Student

 Year

 College

 DOJ

 

Using the above code i get the first value as default value i.e. Name in all the listboxes.

I want my listboxes to have Name in the first listbox,Student in the second listbox,year in the third listbox and so on.

I cannot use :

    <apex:selectOptions value="{!Header[in]}"/>

 As var="in" is of type innerlist of a inner class
I cannot remove the inner class as well because it is getting me the values of selectedvalue1 and selectedvalue2.

 

So please help.

Do i use an another repeat tag with var or what?

 

Thanks.

 

 

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

Just try this...

public class communityCon1Inner
    {
         public string selectedValue1{get;set;}
         public String selectedValue2{set;get;}

         public  communityCon1Inner()

        {
        selectedValue1='Name';

selectedValue2='Student';

        }   
    }

All Answers

Avidev9Avidev9

You just need to take care of the assignment of the Selected value from your controller[ while you are generating/populating the wrappers]

So

 

If you want Name for the first Selectlis, assingn SelectedValue = 'Name' for it

in.selectedValue1 = 'Name'; // here in represents the first value of the wrapper

Similarly for second

in.selectedValue1 = 'Student'

 

 

 

URVASHIURVASHI

Thanks for the reply.

No i cant use it like

in.selectedValue = 'Name'

 

As the values for the  drop down listbox are coming dynamically from a Excel file.

Should i send you my entire code on some personal id?

If you could help would be grateful.

Neha LundNeha Lund

Hi,

 

I guess SelectedValue2 is getting set to 'Name'.

 

Can you please check the Value in your WrapperList...

URVASHIURVASHI

Thanks for the reply.

Yes neha,correct.

But i have a select list within repeat tag.

and for every select list i have the 'Name' value by default.

n i want each of my select list should have a different default value.

Like Name for first select list

Student for second and so on.

 

And in my case:

If you see the code i cannot use

Header[in] as return type of 'in' is not Number(Integer)

So how do i do it.

 

 

Please help.

Yoganand GadekarYoganand Gadekar

Hi,

 

Here's an example for you that shows simple custom picklist implmention in visualforce.

Example for both select option and select options.

 http://cloudforce4u.blogspot.in/2013/06/how-to-implement-custom-picklist-in.html

May be this could help you out.

Hit kudos adn mark this as answer if it helps you out.

 

thanks,

 

Neha LundNeha Lund

Just try this...

public class communityCon1Inner
    {
         public string selectedValue1{get;set;}
         public String selectedValue2{set;get;}

         public  communityCon1Inner()

        {
        selectedValue1='Name';

selectedValue2='Student';

        }   
    }

This was selected as the best answer