<apex:page
controller="AddDeleteRow1" >
<!-- Javascript -->
<script type =
"text/javascript">
function winClose()
{
self.close();
}
</script>
<!-- End of Javascript-->
<apex:form >
<apex:pageBlock >
<apex:pageblockSection >
<apex:pageblocktable
value="{!memberList11}" var="mem">
<apex:column
title="Name" value="{!mem.Name}"/>
<apex:column
title="Brand" value="{!mem.Brand__c}"/>
</apex:pageblocktable>
</apex:pageblockSection>
</apex:pageBlock>
<apex:variable var="rowNum" value="{!0}"/>
<apex:pageBlock id="membAdd" >
<apex:variable var="rowNum"
value="{!0}"/>
<apex:pageblockSection >
<apex:pageBlockTable
value="{!memberAddList}" var="memb">
<apex:facet
name="footer">
<apex:commandLink
value="Add Row" action="{!addRow}"
reRender="membAdd"/>
</apex:facet>
<apex:column headerValue="No."
style="width:20px; text-align:center;"
headerClass="centertext">
<apex:outputText
value="{0,number, ###}" style="text-align:center;">
<apex:param
value="{!rowNum+1}" />
</apex:outputText>
</apex:column>
<apex:column
headerValue="Member Name">
<apex:inputField
value="{!memb.Name}"/>
</apex:column>
<apex:column
headerValue="Cost">
<apex:inputField
value="{!memb.Cost__c}"/>
</apex:column>
<apex:column
headerValue="eMail Id">
<apex:inputField
value="{!memb.Brand__c}"/>
</apex:column>
<apex:column
headerValue="Delete" >
<apex:commandLink
style="font-size:15px; font-weight:bold;
text-align:center;color:red;" value="X"
action="{!delRow}" reRender="membAdd,temp" rendered="{!rowNum>=0}">
<apex:param
value="{!rowNum}" name="index" />
</apex:commandLink>
<apex:variable
var="rowNum" value="{!rowNum+1}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageblockSection>
<apex:pageblockSection columns="1" >
<apex:pageblockSectionItem >
<apex:commandButton
value="Save" action="{!saveMemb}"
onComplete="winClose();"/>
<apex:commandButton value="Cancel"
onclick="winClose();" />
</apex:pageblockSectionItem>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form></apex:page>
public with sharing class
AddDeleteRow1 {
public List<bottle__c>
memberList {get;set;}
public List<bottle__c> memberAddList {get;set;}
public String memberName {get;set;}
public Integer rowNum{get;set;}
public AddDeleteRow1()
{
getmemberList11();
memberAddList = new List<Bottle__c>();
memberAddList.add(new Bottle__c());
}
//List<bottle__c> member{get;set;}
public List<bottle__c> getmemberList11(){
/*String sql = 'SELECT Name,
brand__c FROM bottle__c';
member = Database.Query(sql);*/
memberList = [SELECT Name,
brand__c,cost__c FROM bottle__c LIMIT 10];
return memberList;
}
public void AddRow()
{
memberAddList.add(new bottle__c());
}
public void delRow()
{
rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
memberAddList.remove(rowNum);
}
public void saveMemb()
{
insert memberAddList;
}
}
No comments:
Post a Comment