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
Visweswara Rao PamalaVisweswara Rao Pamala 

Dynamically add rows to vf page

Hi all,

Can you please help me how to add rows dynamically in vf page based on record getting in query in controller.
Below is the code iam using, in this currently adding one row, but need to add rows based on the record getting in SQL query.

VF page:
<apex:page standardController="Opportunity" extensions="ListsControllernew">
  <apex:form >   
<apex:pageBlock title="Files">
     
       <apex:pageBlockButtons location="top" >
               <apex:commandButton value="Upload Files" />
       </apex:pageBlockButtons>
      
      <apex:pageBlockTable value="{!oppname}" var="acc">
            <apex:column headerValue="Action" value="{!oppname}" />
            <apex:column headerValue="Title" value="{!title}" />
            <apex:column headerValue="Last Modified by" value="{!Modified}" />
            <apex:column headerValue="Is Locked" value="{!Lockvalue}" />
           
        </apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller:
public class ListsControllernew  {

    private final Opportunity opp;
    public string title{get; set;}
    public String Modified{get; set;}
    public String Lockvalue{get; set;}
    public String oppname {get; set;}
    
  
    public ListsControllernew(ApexPages.StandardController stdController) {
        this.opp= (Opportunity)stdController.getRecord();
        system.debug('id:'+opp.id);
        //List<Opportunity> customObjects =[select name from Opportunity where Id=:opp.id];
        //SELECT ContentDocumentId, FROM ContentDocumentLink WHERE LinkedEntityId = '[RECORD ID]' 
        integer count = [SELECT count()FROM ContentDocumentLink WHERE LinkedEntityId =: opp.id];
        system.debug('Count:'+count);
        List<ContentDocumentLink> customObjects = [SELECT Id, ContentDocumentId, ContentDocument.LatestPublishedVersionId, ContentDocument.Title, ContentDocument.CreatedById, ContentDocument.LastModifiedDate FROM ContentDocumentLink WHERE LinkedEntityId =: opp.id];
        for (ContentDocumentLink rec: customObjects)
         {
        oppname = rec.ContentDocument.Title;
        title=rec.ContentDocument.Title;
        Modified=rec.ContentDocument.CreatedById;
        Lockvalue= rec.ContentDocument.CreatedById;
         }
        
             
   } 
}

Thanks.
 
SandhyaSandhya (Salesforce Developers) 
Hi Visweswara Rao,

Please refer below sample code which includes add row functionality to bulk update the records.
 
<apex:page Controller="Task12Controller">
 <apex:form >
  <apex:PageBlock >
     <apex:PageBlockTable value="{!bts}" var="bt">
      <apex:column headerValue="BottleName">
      <apex:inputField Value="{!bt.Name}"/>
      </apex:column>
      <apex:column headerValue="cost">
      <apex:inputField Value="{!bt.cost__c}"/>
      </apex:column>
       <apex:column headerValue="Quantity">
      <apex:inputField Value="{!bt.quantity__c}"/>
      </apex:column>
     </apex:PageBlockTable>
    <apex:pageBlockButtons >
    <apex:commandButton value="UpdateBottles" action="{!saveBottle}"/>
   </apex:pageBlockButtons>
  </apex:PageBlock>
 </apex:form>
</apex:page>
 
public with sharing class Task12Controller {
Bottle__c bott =new Bottle__c();
    public List <Bottle__c >bts{get;set;}
    public Task12Controller()
    {
     bts=new list<Bottle__c>();
     bts=[select id,Name,cost__c,quantity__c from Bottle__c];
           
    }
    public PageReference saveBottle() {   
        update bts;
        return Page.Task11SavePage;
    }

    
}

Hope this helps you!

If this helps you please mark it as BestAnswer so that it will make available for others as a proper solution.

Thanks and Regards
Sandhya