Radio Button selected by default in Visualforce page


Below is the simple code to select Radio button by default in Visualforce page.


Visualforce:


<apex:selectRadio value="{!searchCategory}" >
    <apex:selectOption itemValue="Member" itemlabel="Member"/>
    <apex:selectOption itemValue="Blog" itemlabel="Blog"/>
    <apex:selectOption itemValue="Photo" itemlabel="Photo"/>
</apex:selectRadio>


Apex:


public class search 
{
..........................................................
..........................................................
// Constructor of the class
public search()
{
searchCategory = 'Member';
}
..........................................................
..........................................................
}

2 comments:

  1. Very poor post. Member searchCategory is not defined at all. Also since the value can be changed by the user though a radio selection you should have introduced the concept of read-only and writable members which is not discussed at all. Your code snippet is short but with four of five lines more you could have done a better job. Your code took as it is serves no purpose.

    ReplyDelete
    Replies
    1. Hi,
      That is why I have added "...................".

      This is a sample code!

      Delete

Sharing is Caring!!! Share this with your friends!!!

submit to reddit