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
piyush316piyush316 

Delete a particular row on a button click from a page block table

This is my code in which im able to add a new row on click of the Add button..

 

1) I have a delete button for each row whenever the row is add..

2) I want to delete a particular row when i click the delete button....

3) Can i make use of indexes to get the particular row id to delete a particular row..How can i achieve the delete functionality

 

 

<!-- This is my visual force page-->

 

<apex:page standardController="Account" extensions="adddel">
    <apex:form >
        <apex:pageBlock >
       
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" rerender="error"/>
                <apex:commandButton value="Add Row" action="{!addRow}" rerender="table,error"/>
            </apex:pageBlockButtons>
       
       
       
            <apex:pageBlockTable value="{!accts}" var="a" id="table" >
                <apex:column >
                    <apex:commandButton value="Del Row" action="{!delRow}" rerender="table,error"/>
                </apex:column> 
       
                <apex:column headerValue="Name">
                    <apex:inputField value="{!a.Name}"/>
                </apex:column>
               
                              
                 <apex:column headerValue="Phone">
                    <apex:inputField value="{!a.Phone}"/>
                </apex:column>          
            </apex:pageBlockTable>
           
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

<!--This is My Controller Class-->

 

public class adddel
{

    public List<Account> accts {get; set;}
   
   
    public adddel(ApexPages.StandardController ctlr)
    {
        accts = new List<Account>();
        accts.add(new Account());
       
    }
   
   
   
    public void addrow()
    {
        accts.add(new Account());
    }
   
   public void delrow()
   {
       

   }
   
    public PageReference save()
    {
        insert accts;
        //PageReference home = new PageReference('/home/home.jsp');
           //home.setRedirect(true);
        return null;
    }

}