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
deepak kumar 13deepak kumar 13 

How to add and remove rows dynamically in visualforce page

Hi all,

I have a requirement that i have to display 3 objects like contact,user and lead. According to the object selection it should display all fields of the corresponding object in dropdown list,also operators in dropdown and search value in input text box in a single row.

When i select add row button it should add one more row with corresponding object fields,operators and search text box and when i click remove row button it should remove rows.How can i approach this.?.

Thanks in advance,
Mudasir WaniMudasir Wani
Dear Deepak,

Here is a blog you can refer.

For adding a row you need to follow these steps
Let me explain it for contact.
//First create a list of contacts
List<Contact> conList = new List<Contact>();

public void addRow(){
Contact con = new Contact();
   conList .add(con);

Page Should have a section which you will render after every Hit
<apex:outputPanel id="panelId">
         //Code to display contact list add a command button with delete row and It should contain row number then you can use list.remove function 
<apex:commandButton value="Add Row" action="{!addRows}" />

Donot forget to select best answer to make our efforts visible in the developer forum.

Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Hi All,

         I am also having the same issue . I posted my code below

My code:

public void addrow()
        rowlist = new List<Sobject>();
        sno = value.size();    
        for(Sobject s:val4)
            wrapperclass wr = new wrapperclass('s.Email','s.Name',false,,sno);   
deepak kumar 13deepak kumar 13
Thanks for your reply Mudasir wani, i want to display corresponding object fields,operators and search text box like standard Filter condition not only for contacts.Its according to the selection of objects like contact,user and lead.

For example, if i select user object in dropdown. in filter condition it should display those user fields,operators and search box.When i click add row button it should add one more row with user fields,operators and search box in another row.