function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SimrinSimrin 

Add row dynamically on button click

<apex:variable var="count" value="{!1}"/>
   
         <apex:commandButton action="{!add}"  id="button" styleClass="button"  image="{!URLFOR($Resource.add)}" reRender="idForm">
                <apex:param name="paramValue2" value="{!count}" assignTo="{!rows}"/>
            </apex:commandButton>
            <apex:variable var="count" value="{!count + 1}"/>


<apex:selectList size="1" value="{!operator}" id="operator" styleClass="basic">
                <apex:selectOption itemValue="Select Operator"/> 
                <apex:selectOption itemLabel="Equals" itemValue="="/>
                <apex:selectOption itemLabel="Greater or equals to" itemValue=">="/>
                <apex:selectOption itemLabel="Lesser or equals to" itemValue="<="/>
            </apex:selectList>
Hello,

I want a use case where user clicks on a button and the selectlist is added.

One cleick one select list is added and it will happen consecutiveely.

I also want to have appropriate controller.

Any tutorial on net will be helpful

Thanks
Best Answer chosen by Simrin
MagulanDuraipandianMagulanDuraipandian
Check this - http://www.infallibletechie.com/2012/06/dynamically-adding-rows-in-apex.html

All Answers

MagulanDuraipandianMagulanDuraipandian
Check this - http://www.infallibletechie.com/2012/06/dynamically-adding-rows-in-apex.html
This was selected as the best answer
NagaNaga (Salesforce Developers) 
Hi Simrin,

Please see the following code below

User-added imagePlease see the link below for more information

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000963NIAQ

Best Regards
NagaKiran
ManojjenaManojjena
Hi Simrin ,

Below code snippet will solve your problem .
 
public class OperatorPiclListAddDelete{
    public String rows{get;set;}
    public String operator{get;set;}
    public List<OperatorWrapper> wrpList {get;set;}
    public Integer count{get;set;}
    public OperatorPiclListAddDelete(){
        wrpList = new List<OperatorWrapper>();
        wrpList.add(new OperatorWrapper());
    }
    public void add(){
       wrpList.add(new OperatorWrapper());
    } 
   public class OperatorWrapper{
	   public OperatorWrapper(){
	   
	   }
	}
}

<apex:page controller="OperatorPiclListAddDelete" id="Pg">
	<apex:form id="frm">
	<apex:pageBlock id="membAdd" >                  
		<apex:variable value="{!0}" var="count"/>
			<apex:pageBlockTable value="{!wrpList}" var="acc">
				<apex:column >
					<apex:selectList size="1" value="{!operator}" id="operator" styleClass="basic">
					<apex:selectOption itemValue="Select Operator"/> 
					<apex:selectOption itemLabel="Equals" itemValue="="/>
					<apex:selectOption itemLabel="Greater or equals to" itemValue=">="/>
					<apex:selectOption itemLabel="Lesser or equals to" itemValue="<="/>
					</apex:selectList>
				</apex:column> 
			</apex:pageBlockTable> 
		<apex:variable value="{!count+1}" var="count"/> 
		<apex:pageBlockButtons location="Bottom">
		<apex:commandbutton value="Add" action="{!add}"  image="{!URLFOR($Resource.add)}" Style="height :100px ; width :100 px;" rerender="membAdd"/>
		</apex:pageBlockButtons>      
	</apex:pageBlock>
	</apex:form>
</apex:page>