
10 réponses

VF PAGE<apex:page Controller="proj1" docType="html-5.0" > <apex:form > <apex:selectList size="1" value="{!searchstring}"> <apex:selectOptions value="{!listOfStrings }"/> </apex:selectList> <apex:commandButton value="Search records" action="{!search}" /> <apex:commandButton value="Clear records" action="{!clear}" /> <apex:pageBlock title="Search Result"> <apex:pageblockTable value="{!acc}" var="a"> <apex:column value="{!a.name}"/> <apex:column value="{!a.ProductCode }"/> <apex:column value="{!a.Quantity__c}"/> <apex:column value="{!a.UnitPrice__c}"/> <apex:column > <apex:commandButton value="AddToCart" /> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>CONTROLLERpublic with sharing class proj1{ public String Product2{ get; set; }public list <Product2> acc {get;set;} public string searchstring {get;set;} public list<Selectoption> listOfStrings {get; set;}public proj1( ) { listOfStrings = new List<Selectoption>(); for(Product2 a: [SELECT Name, ProductCode,IsActive From Product2 LIMIT 50]) listOfStrings.add(new selectoption(a.name,a.name)); // listOfStrings.add(a.name);} public void search(){string searchquery='select name,ProductCode,Quantity__c,UnitPrice__c from product2 where name like \'%'+searchstring +'%\' Limit 30';acc= Database.query(searchquery); }public void clear(){ acc.clear(); } }