+ Start a Discussion

radio button in a table


          i want to try somthing like this......

         Add a field ‘Primary Contact’ on Account, which would be a lookup to Contact object. Add a button on Account Detail      page labeled ‘Select Primary Contact’. On click of this button, a page should come up with list of all contacts associated with this Account in a table format. The left most column of this table would be a radio button. User should be able to select one contact and submit this page. On submission, the selected contact would become Primary Contact for this account and user would be redirected back to Account detail page.


      here i face a problem to create a table with selectradio button



Hi ,

What is the issue with that , you can use the HTML input component for that as below:-

<input type="radio" name="color" id="{con.id}" value="{con.id}"> 

the above code will assign dynamic  ids to the radio buttons when used within any iterations.


Hope this helps...


thanks for reply 

   but i want use <apex:selectradio> button          here is my code using  <input type="radio"> and this is working 




<apex:page standardController="Account" extensions="RadioButton" showheader="false">
<apex:form >
<apex:pageblock id="allcons" title="Available Contacts">
<apex:pageblocktable id="allcons" value="{!AllContacts}" var="allcon">

<apex:column headervalue="Set as Primary">
<apex:actionSupport action="{!selectcon}" event="onclick" reRender="hidden">
<input type="radio" name = "selectedContact">
<apex:param name="conid" value="{!allcon.Id}"/ >

<apex:column headervalue="Last Name">
<apex:outputfield value="{!allcon.LastName}"/>

<apex:column headervalue="First Name">
<apex:outputfield value="{!allcon.FirstName}"/>

<apex:column headervalue="Email">
<apex:outputfield value="{!allcon.Email}"/>

<apex:column headervalue="Phone">
<apex:outputfield value="{!allcon.Phone}"/>


<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton action="{!back}" value="Cancel"/>


<apex:pageBlock id="hidden" rendered="false"></apex:pageBlock>

public class RadioButton {

    public RadioButton(ApexPages.StandardController controller) {


public Contact con;
public Account acc;
public String selcontactid;
Public List<contact> getAllContacts()
acc = [select id,primary_contact__c from account where id = :Apexpages.currentPage().getParameters().get('id')];
List<contact> allcons = [Select Id,FirstName,LastName,Email,Phone from Contact where accountId = :Apexpages.currentPage().getParameters().get('id')];
return allcons;

Public void selectCon()
selcontactid = System.currentPagereference().getParameters().get('conid');

public pageReference save(){
acc.primary_contact__c = selcontactid ;
update acc;
return back();


Pramodh KumarPramodh Kumar

Did you find any solution for the <apex:selectRadio> tag, I have similar kind of scenario.
If i use selectRadio tag, the radio button are moving to the next row referred in the figure.

User-added image
Here is my code.
<apex:selectRadio value="{!survey__c.Sales__c}">
                     <apex:selectOption itemValue="Poor"/>
                  <apex:selectOption itemValue="Average"/> 
                 <apex:selectOption itemValue="Good"/> 

Please let me know if you have any solution or any idea.