Labels

Friday, April 27, 2012

DROPDOWN SELECTION & DISPLY SELECECTED ITEM DATA

Create Book Oject like
BookName
Price
Title












Create Apex Class

public class BookDropdown
{
List<Book__c> l;
public String Opn{
 get { return Opn; }
 set { Opn= value; }
}
public List<Book__c> getL()
{

l=[SELECT Price__c,title__c FROM Book__c where Id=:this.Opn];
  return l;
   } 
public Double price
{
 get { return price; }
      set { price= value; }
      }
public String title
{
 get { return title; }
      set { title= value; }
}
public String head
{
 get { return head; }
      set { head= value; }
}
public String str
{
 get { return str; }
      set { str= value; }
}
   public List<SelectOption> getBks()
   {
      
       List<SelectOption> options = new List<SelectOption>(); //new list for holding all of the picklist options
       // options.add(new selectOption('1', '- None -')); //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below
       options.add(new SelectOption('1', '-select-'));
        for (Book__c bk : [SELECT Price__c,title__c FROM Book__c])
        { //query for User records with System Admin profile
        if(bk!=null&&bk.title__c!=null)
            options.add(new SelectOption(''+bk.Id, ''+bk.title__c )); //for all records found - add them to the picklist options
        }
   
           return options;
        
        }//return the picklist options
}

Web hosting Create Visual force page
<apex:page controller="BookDropdown">
   <apex:form >
    <apex:actionFunction name="rerenderStates" rerender="list" >
          <apex:param name="firstParam" assignTo="{!opn}" value="" />
      </apex:actionFunction>
   <apex:message rendered="true" />
      <apex:pageBlock mode="edit" id="block">
        
        
            <apex:pageBlockSection >
              <apex:pageBlockSectionItem >
                 <apex:outputLabel value="DropDownBook: " for="themesList"/>
                   <apex:selectList id="themesList" size="1" value="{!opn}" onChange="rerenderStates(this.value)">
                       <apex:selectOptions value="{!bks}"/>
                   </apex:selectList>
              </apex:pageBlockSectionItem>
           </apex:pageBlockSection>
         
           <apex:actionStatus id="status" startText="requesting..."/>
        <apex:pageBlockSection title="{!head}" id="results" columns="1">
           <apex:pageBlockTable id="list" value="{!l}" var="i" rendered="{!NOT(ISNULL(l))}">
              <apex:column value="{!i.price__c}"/>
              <apex:column value="{!i.title__c}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>

      </apex:pageBlock>
   </apex:form>
</apex:page>

type url in address bar
https://c.ap1.visual.force.com/apex/BookDropdown
u get

No comments:

Post a Comment