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
Rakesh MRakesh M 

how to add row?

Admin Requirement:
When I click on add button one more InvoicelineItem  row should be added to pageBlockTable.
Please help me in achieving this functionality.
User-added image

User-added image
Code:
public class InvoiceLineItem {
    public string ProdName{set;get;}
    public decimal Quantity{set;get;}
    public decimal price{set;get;}
    public string tax{set;get;}
    public string productfamily{set;get;}
    public list<InvoiceLineItem__c> Ili{set;get;}
    public InvoiceLineItem__c I{set;get;}
    public InvoiceLineItem(){
        Ili= [select ProductName_c,Quantityc,Pricec,productc from InvoiceLineItem_c];        
    }
    public void Add(){
        Ili = new list<InvoiceLineItem__c>();
        I = new InvoiceLineItem__c();
        I.ProductName__c=ProdName;
        I.Quantity__c=Quantity;
        I.Price__c=Price;
        I.Product__c=productfamily;
        Ili.add(I);
        insert Ili;        
    }   
}
<apex:page controller="InvoiceLineItem">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!Ili}" var="a">
                <apex:column headerValue="ProdName">
                    <apex:inputText value="{!a.ProductName__c}"/>
                </apex:column>
                <apex:column headerValue="Quantity">
                    <apex:inputText value="{!a.Quantity__c}"/>
                </apex:column>
                <apex:column headerValue="Price">
                    <apex:inputText value="{!a.Price__c}"/>
                </apex:column>
                <apex:column headerValue="ProductFamily">
                    <apex:inputText value="{!a.Product__c}"/>
                </apex:column>
                <apex:column >
                    <apex:commandButton value="Add" action="{!Add}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Thanks in advance.
SandhyaSandhya (Salesforce Developers) 
Hi,

Try changing your code as below in constructor
public InvoiceLineItem(){
        Ili= [select ProductName_c,Quantityc,Pricec,productc from InvoiceLineItem_c];   
lli.add(l);     
    }
Thanks and Regards
Sandhya


 
RbnRbn
Hi Rakesh,

Please go through the below blog which would help u in attaining the above functionality:


http://salesforceworld4u.blogspot.ca/2014/01/addremove-functionality-in-vf-page-for.html


Regrds,
Rabi