+ Start a Discussion

Dynamically add columns to the pageblock table

I have one object


if I am giving as input it should add 10 input fields to the pageblocktable and when i am clicking the save, it should save 10 values in the database. If I am giving 5 so it should add 5 input text to the pageblocktable in the visualforce page and 5 values should save in the database.Based on the input number dynamically the columns should add to the pageblocktable.

Any help is greatly appreciated


I wrote a blog post on exactly this topic a while ago:




Make a function in a class, that call on button click. 


In this function make a for loop and in this loop make a new insatance of object. like


public list<object__c> dynamiclist {get;set;}


public void addRows()


   integer i;

  for(i = 0 ; i<5; i++)


         object__c obj = new object__c();






this i value you will set by a page and dynamic list is bind with <apex:repeat> in visualforce page.


* Mark this as solution for others to get it easily



Thank You