Ex:1
Visualforce Page:
<apex:page controller="selectradiocls" >
<apex:form >
<apex:SelectRadio value="{!selected}" layout="pagedirection">
<apex:selectOptions value="{!items}"/>
</apex:SelectRadio>
<apex:commandButton value="Select" action="{!showselected}" />
</apex:form>
</apex:page>
Apex Class:
public with sharing class selectradiocls {
public PageReference showselected() {
System.debug('----------->'+selected);
return null;
}
public string selected{get; set;}
public List<SelectOption> getitems(){
List<SelectOption> options = new List<SelectOption>();
List<Account> lst=[Select id, name from Account];
for(Account a:lst){
options.add(new selectOption(a.id,a.name));
}
return options;
}
}
Ex:2
Visualforce Page:
<apex:page controller="sampleCon">
<apex:form >
<apex:selectRadio value="{!country}">
<apex:selectOptions value="{!items}"/>
</apex:selectRadio><p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
</apex:page>
Apex Class:
public class sampleCon {
String country = null;
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico')); return options;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
Visualforce Page:
<apex:page controller="selectradiocls" >
<apex:form >
<apex:SelectRadio value="{!selected}" layout="pagedirection">
<apex:selectOptions value="{!items}"/>
</apex:SelectRadio>
<apex:commandButton value="Select" action="{!showselected}" />
</apex:form>
</apex:page>
Apex Class:
public with sharing class selectradiocls {
public PageReference showselected() {
System.debug('----------->'+selected);
return null;
}
public string selected{get; set;}
public List<SelectOption> getitems(){
List<SelectOption> options = new List<SelectOption>();
List<Account> lst=[Select id, name from Account];
for(Account a:lst){
options.add(new selectOption(a.id,a.name));
}
return options;
}
}
Ex:2
Visualforce Page:
<apex:page controller="sampleCon">
<apex:form >
<apex:selectRadio value="{!country}">
<apex:selectOptions value="{!items}"/>
</apex:selectRadio><p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
</apex:page>
Apex Class:
public class sampleCon {
String country = null;
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico')); return options;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
No comments:
Post a Comment