RADIOBUTTON IN A DATATABLE IN VISUALFORCE PAGE | Techila
1961
single,single-post,postid-1961,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive
 

RADIOBUTTON IN A DATATABLE IN VISUALFORCE PAGE

RADIOBUTTON IN A DATATABLE IN VISUALFORCE PAGE

RADIOBUTTON IN A DATATABLE IN VISUALFORCE PAGE

As the title of the article implies, in this post we will be seeing an example which uses radio button in a table in Visualforce and allows selecting one of the records in the table.

You can see a demo of the example here – Click here (forcetreedemos)

Visualforce Page:

<apex:page controller=”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=”consel,allcons”> 

                        <input type=”radio” />                   

                            <apex:param name=”conid” value=”{!allcon.Id}”>

                        </apex:param></apex:actionsupport>                           

                    </apex:column>   

                    <apex:column headervalue=”Last Name”>

                        <apex:outputfield value=”{!allcon.LastName}”>

                    </apex:outputfield></apex:column>

                    <apex:column headervalue=”First Name”>

                        <apex:outputfield value=”{!allcon.FirstName}”>

                    </apex:outputfield></apex:column> 

                    <apex:column headervalue=”Email”>

                        <apex:outputfield value=”{!allcon.Email}”>

                    </apex:outputfield></apex:column> 

                    <apex:column headervalue=”Phone”>

                        <apex:outputfield value=”{!allcon.Phone}”>

                    </apex:outputfield></apex:column> 

                </apex:pageblocktable>

</apex:pageblock>

<apex:pageblock id=”consel” title=”Selected Contact”>

            <apex:pageblocktable id=”allcons” value=”{!selectedContact}” var=”selcon”>                      

                    <apex:column headervalue=”Last Name”>

                        <apex:outputfield value=”{!selcon.LastName}”>

                    </apex:outputfield></apex:column>

                    <apex:column headervalue=”First Name”>

                        <apex:outputfield value=”{!selcon.FirstName}”>

                    </apex:outputfield></apex:column> 

                    <apex:column headervalue=”Email”>

                        <apex:outputfield value=”{!selcon.Email}”>

                    </apex:outputfield></apex:column> 

                    <apex:column headervalue=”Phone”>

                        <apex:outputfield value=”{!selcon.Phone}”>

                    </apex:outputfield></apex:column> 

                </apex:pageblocktable>

</apex:pageblock>              

</apex:form>

</apex:page>

Apex Class: RadioButton

public class RadioButton {

List<contact> selectcon;

Public List<contact> getAllContacts()

{

    List<contact> allcons = [Select Id,FirstName,LastName,Email,Phone from Contact limit 5];

    return allcons;

}   

Public void selectcon()

{

    String selcontactid = System.currentPagereference().getParameters().get(‘conid’);

    Contact con = [Select Id,FirstName,LastName,Email,Phone from Contact where Id=:selcontactid];

    selectcon =  new List<contact>();

    selectcon.add(con);

}

Public List<contact> getselectedContact()

{

    return selectcon;

}

}

Courtesy: http://www.forcetree.com/2011/09/radiobutton-in-datatable-in-visualforce.html
http://pulse7.net/wp-content/uploads/2016/01/RadioButton.png

“Know more about Salesforce Consulting at Techila”

Author: techila

No Comments

Post A Comment