+ Start a Discussion
prasanth puvvada 4prasanth puvvada 4 

list<selectoption> addall() method is not loading in vf page.

hello sir, i am trying to create a radio button in vf page and getting the values from apex page.  so i created this code using LIST concept. If i am trying to add one by one selectoption value then they are displaying IF i am trying to add all values using ADDALL(); then it is not loading.  please help.
 
last two lines of code for adding all selectoptions values to the list. not showing any error while saving, but output not coming at VF page. 

public class radio1
{
public string result{set;get;}

public List<selectoption> radios{set;get;}

public radio1()
{
radios=new list<selectoption>();

selectoption op1=new selectoption('prasanth','prasanth');
selectoption op2=new selectoption('Ramcharan','Ramcharan');
selectoption op3=new selectoption('pavan kalyan','pavan kalyan');
selectoption op4=new selectoption('balakrishna','balakrishna');
selectoption op5=new selectoption('mahesh','mahesh');

radios.add(op1);

list<selectoption> mylist=new list<selectoption>();
mylist.addall(radios);

}
}
 
VF page. 

<apex:page controller="radio1">
<apex:form >
<apex:pageblock >
  
  <apex:outputlabel value="radio buttons" /><br/>
  <apex:outputText value="radio buttons"  /><br/><br/><br/>
  
  <apex:selectRadio value="{!result}" title="hello" label="hi">
  <apex:selectoptions value="{!radios}" />  
  
  </apex:selectRadio>
  
  
  
  
</apex:pageblock>
</apex:form>  
</apex:page>

User-added image
Amit Chaudhary 8Amit Chaudhary 8
Please try below code :-
public class radio1
{
public string result{set;get;}

public List<selectoption> radios{set;get;}

public radio1()
{
radios=new list<selectoption>();

selectoption op1=new selectoption('prasanth','prasanth');
selectoption op2=new selectoption('Ramcharan','Ramcharan');
selectoption op3=new selectoption('pavan kalyan','pavan kalyan');
selectoption op4=new selectoption('balakrishna','balakrishna');
selectoption op5=new selectoption('mahesh','mahesh');

radios.add(op1);
radios.add(op2);
radios.add(op3);
radios.add(op4);
radios.add(op5);

list<selectoption> mylist=new list<selectoption>();
mylist.addall(radios);

}
}

In below code first you need to add values in "radios" list then you can add all values of "radios" in other picklist "mylist"

radios.add(op1);
radios.add(op2);
radios.add(op3);
radios.add(op4);
radios.add(op5);

list<selectoption> mylist=new list<selectoption>();
mylist.addall(radios);

If you want to see out put of both list. Then please try below code :-
<apex:page controller="radio1">
<apex:form >
<apex:pageblock >
  
  <apex:outputlabel value="radio buttons" /><br/>
  <apex:outputText value="radio buttons"  /><br/><br/><br/>
  
  <apex:selectRadio value="{!result}" title="hello" label="hi">
      <apex:selectoptions value="{!radios}" />  
  </apex:selectRadio>
  
  Out of Add All List    
  <apex:selectRadio value="{!result}" title="hello" label="hi">
      <apex:selectoptions value="{!mylist}" />  
  </apex:selectRadio>
  
  
  
</apex:pageblock>
</apex:form>  
</apex:page>
public class radio1
{
public string result{set;get;}

public List<selectoption> radios{set;get;}
public List<selectoption> mylist{set;get;}

public radio1()
{
    radios=new list<selectoption>();
    
    selectoption op1=new selectoption('prasanth','prasanth');
    selectoption op2=new selectoption('Ramcharan','Ramcharan');
    selectoption op3=new selectoption('pavan kalyan','pavan kalyan');
    selectoption op4=new selectoption('balakrishna','balakrishna');
    selectoption op5=new selectoption('mahesh','mahesh');
    
    radios.add(op1);
    radios.add(op2);
    radios.add(op3);
    radios.add(op4);
    radios.add(op5);
    
    mylist=new list<selectoption>();
    mylist.addall(radios);
    
}
}
I hope this will help you. Please let us know if this will help you