+ Start a Discussion
SapanaSapana 

display list of records using pageblocktable

I wanted to display list on records of object  on a detail page of some other object

I have done so by using pageblock table, but i want to display edit and delete link adjacent to each record and also a new record button  similar to that in a related list. how could this be done?

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet as reference:

 

////////////////////// Controller /////////////////////////////////////////////////////

public class Material

{

   list<MaterialRequest__c> mReq=new list<MaterialRequest__c>();

   public integer countVal{get;set;}

    public integer count{get;set;}

    public list<wrap> wrap1{get;set;}

    public Material()

    {

    count=0;

    count++;

    wrap1=new list<wrap>();

    wrap w=new wrap();

    w.count=count;

    w.mreq=new MaterialRequest__c();

    wrap1.add(w);

    //wrap1.mreq =new MaterialRequest__c();

    }

    public void save()

    {

     

    for(wrap w:wrap1)

    {

    MaterialRequest__c m1=new MaterialRequest__c();

    m1.Contact__c=w.mreq.Contact__c;

    m1.MaterialName__c=w.mreq.MaterialName__c;

    m1.Quantity__c=w.mreq.Quantity__c;

    m1.unit_price__c=w.mreq.unit_price__c;

    mReq.add(m1);

    }

    insert mReq;

    }

    public void AddMore()

    {

    count++;

    wrap w1=new wrap();

    w1.count=count;

    w1.mreq= new MaterialRequest__c();

    wrap1.add(w1);

    }

    public void del()

    {

    system.debug('####################'+countVal);

   

    wrap1.remove(countVal-1);

    count--;

    for(wrap w:wrap1)

    {

   

    if(w.count>countVal)

    {

    w.count=w.count-1;

    }

     //w.count=count;

     //wrap1.add(w);

     system.debug('###############-------------------' +wrap1);

     //update wrap1;

     //count++;

     }

    //update wrap1;

    system.debug('@@@@@@@@@@@@@@@@@@@' + wrap1);

    }

    public class wrap

    {

     public integer count{get;set;}

     public MaterialRequest__c mreq{get;set;}

    }

}

//////////////////////////// VF page ////////////////////////////////////////

<apex:page controller="Material">

<apex:form >

  <apex:tabPanel >

      <apex:tab label="Material" id="repeatid11" >

      <apex:outputPanel id="panelid">

          <apex:repeat value="{!wrap1}" var="w" id="repeatid" >

          <div><table><center><b>Material Request {!w.count}</b></center>

              <tr><td>

              Contact Name</td><td><apex:inputField value="{!w.mreq.Contact__c}"/></td></tr>

              <tr><td>

             Material Name</td><td><apex:inputField value="{!w.mreq.MaterialName__c}"/></td></tr>

             <tr><td>

             Unit Price1</td><td><apex:inputField value="{!w.mreq.Unit_Price__c}"/></td></tr>

             <tr><td>

             Quantity</td><td><apex:inputField value="{!w.mreq.Quantity__c}"/></td></tr>

             </table></div>

            

             <p><center><apex:commandButton value="Delete"  reRender="panelid"   onclick="return showPop('{!w.count}');" >

                

                       

             

                 <!--<apex:param name="test" value="{!w.count}" assignTo="{!countVal}"/>-->

                 </apex:commandButton></center>

             </p>

            <!-- <apex:actionFunction action="{!del}" name="Hey">

                 <apex:param name="va" value="" assignTo="{!countVal}"/>

             </apex:actionFunction>-->

            

             <hr/>

            

          </apex:repeat>

          <apex:actionFunction action="{!del}" name="aaaa" reRender="panelid" >

                 <apex:param name="abc" value="" assignTo="{!countVal}"/>

             </apex:actionFunction>

             <script>

                 function showPop(dc)

                 {

                 var abc=dc;

                 if(confirm("Are sure want to delete?"))

                 aaaa(abc);

                 }

             </script>

          <!--<apex:actionFunction action="{!del}" name="show" reRender="panelid"/>-->

          <p><apex:commandButton value="Save" action="{!save}"/></p>

          <b><apex:commandLink value="AddMore Records" action="{!AddMore}"/></b>

          </apex:outputPanel>

         

      </apex:tab>

  </apex:tabPanel>

</apex:form> 

</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Abhay AroraAbhay Arora

Hi ,

 

Please check below URL to understand what exactly you need to get required UI

http://wiki.developerforce.com/page/Wrapper_Class

 

Thanks

Abhay Arora