# How To Get Item Amount Total And Discount Total Amount [Answered]RSS

Last post Aug 30, 2017 06:25 AM by Eric Du

• asp.ambur

Member

399 Points

1101 Posts

### How To Get Item Amount Total And Discount Total Amount

Hello

I'm using this in my aspx page

https://forums.asp.net/post/6156697.aspx

I want to Item Amount Column Total In Footer & Discount Amount Column Total

How to do using my code....

Thank You

• Eric Du

Contributor

6710 Points

2715 Posts

### Re: How To Get Item Amount Total And Discount Total Amount

Aug 30, 2017 06:25 AM|Eric Du|LINK

Hi asp.ambur,

Sample Code:

```<head runat="server">
<title></title>
<script>
//get Forwarding Packing Tax
\$("select[class='textSelector']").change(function () {
var itemtotalamout = \$("input[id\$='AmountTotal']").val();
var Forwarding = \$("input[id\$='Famt']").val();
var pack = \$("input[id\$='Pack']").val();
var gtotal = parseFloat(itemtotalamout);
var packingtax = \$("select[class='textSelector'] option:selected").text();
var floattaxsting = packingtax.split(" ")[0]
var floattax = parseFloat(floattaxsting) / 100;
var pack = \$("input[id\$='Pack']").val();
var msi = \$("input[id\$='MIS']").val();
var roundoff = \$("input[id\$='Roff']").val();
var Forwarding = \$("input[id\$='Famt']").val();
if (pack == "") {
Fpt = parseInt(Forwarding) * floattax;
\$("input[id\$='TextBox4']").val(Math.round(Fpt * 100) / 100);
}
if (Forwarding == "") {
var Fpt = parseInt(pack) * floattax;
\$("input[id\$='TextBox4']").val(Math.round(Fpt * 100) / 100);
}
if (pack != "" && Forwarding != "") {
var Fpt = (parseInt(pack) + parseInt(Forwarding)) * floattax;
\$("input[id\$='TextBox4']").val(Math.round(Fpt * 100) / 100);
}
if (pack == "" && Forwarding == "") {
\$("input[id\$='TextBox4']").val(" ");
}
var fpt = \$("input[id\$='TextBox4']").val();
if (Forwarding != "") {
gtotal += parseInt(Forwarding);
}
if (pack != "") {
gtotal += parseInt(pack);;
}
if (fpt != "") {
gtotal += parseFloat(fpt);
}
if (msi != "") {
gtotal += parseInt(msi);
}
if (roundoff != "") {
gtotal += parseFloat(roundoff);
}
var totalint = parseFloat(Math.round(gtotal * 100) / 100);
\$("input[id\$='GT']").val(totalint);
})
//get G.Total

\$("input[id\$='MIS']").change(function () {
var itemtotalamout = \$("input[id\$='AmountTotal']").val();
var Forwarding = \$("input[id\$='Famt']").val();
var pack = \$("input[id\$='Pack']").val();
var fpt = \$("input[id\$='TextBox4']").val();
var msi = \$(this).val();
var gtotal = parseFloat(itemtotalamout);
if (Forwarding != "") {
gtotal += parseInt(Forwarding);
}
if (pack != "") {
gtotal += parseInt(pack);
}
if (fpt != "") {
gtotal += parseFloat(fpt);
}
if (msi != "") {
gtotal += parseInt(msi);
}
var totalint = parseFloat(Math.round(gtotal * 100) / 100);
\$("input[id\$='GT']").val(totalint);
});
\$("input[id\$='Roff']").change(function () {
var itemtotalamout = \$("input[id\$='AmountTotal']").val();
var Forwarding = \$("input[id\$='Famt']").val();
var pack = \$("input[id\$='Pack']").val();
var fpt = \$("input[id\$='TextBox4']").val();
var msi = \$("input[id\$='MIS']").val();
var gtotal = parseFloat(itemtotalamout);
if (Forwarding != "") {
gtotal += parseInt(Forwarding);
}
if (pack != "") {
gtotal += parseInt(pack);
}
if (fpt != "") {
gtotal += parseFloat(fpt);
}

if (msi != "") {
gtotal += parseInt(msi);
}
gtotal += parseFloat(\$(this).val());
var totalint = parseFloat(Math.round(gtotal * 100) / 100);
\$("input[id\$='GT']").val(totalint);
//  var gtotal = parseFloat(itemtotalamout) + parseInt(Forwarding) + parseInt(pack) + parseFloat(fpt) + parseInt(msi) + parseFloat(\$(this).val());
})

\$("input[id*='LTQ']").each(function () {
\$(this).change(function () {
var chkSelectcheckbox = \$(this).closest("tr").find("input[type ='checkbox']");
if (chkSelectcheckbox.prop('checked')) {
var Rate = \$(this).parent().prev().prev().find("input[id*='TextBox1']").val();
var ItemAmount = parseInt(Rate) * parseInt(\$(this).val());
var ItemAmounttxt = \$(this).parent().next().find("input[id*='LCA']");
ItemAmounttxt.val(ItemAmount);

debugger;

var amountvalue = 0;
var list = \$("input[id*='LCA']");
for (var i = 0; i < list.length; i++) {
if (list.eq(i).val() == "") {
amountvalue = amountvalue + 0;
}
else {
amountvalue += parseFloat(list.eq(i).val());
}
}
\$("#GridView2_TextBox2").val(amountvalue);

}
})
})
\$("input[id*='TDPerc']").each(function () {
\$(this).change(function () {
var chkSelectcheckbox = \$(this).closest("tr").find("input[type ='checkbox']");
if (chkSelectcheckbox.prop('checked')) {
var InvoiQuantity = \$(this).parent().prev().prev().find("input[id*='LTQ']").val();
var Discount = \$(this).val();
var ItemAmount = \$(this).parent().prev().find("input[id*='LCA']").val();
var DiscountAmounttxt = \$(this).parent().next().find("input[id*='TDAmt']").val(InvoiQuantity);
var AmountAfterDiscount = parseInt(ItemAmount) - parseInt(InvoiQuantity);
var AmountAfterDiscounttxt = \$(this).parent().next().next().find("input[id*='TAmtAfterDis']").val(AmountAfterDiscount);
var TaxFormatval = \$(this).parent().prevAll().eq(6).find("span[id*='LTaxFormat']").text();

// GetAmount
var Newamountvalue = 0;
var list = \$("input[id*='TDAmt']");
for (var i = 0; i < list.length; i++) {
if (list.eq(i).val() == "") {
Newamountvalue = Newamountvalue + 0;
}
else {
Newamountvalue += parseFloat(list.eq(i).val());
}
}
\$("#GridView2_TextBox3").val(Newamountvalue);

if (TaxFormatval == "CGST+SGST") {
var Tax = \$(this).parent().prevAll().eq(5).find("span[id*='LTax']").text()
var taxdividebytwo = parseFloat(Tax) / 200;
var SGSTCGSTval = AmountAfterDiscount * taxdividebytwo;
\$(this).parent().nextAll().eq(2).find("input[id*='TCGST']").val(SGSTCGSTval);
\$(this).parent().nextAll().eq(3).find("input[id*='TSGST']").val(SGSTCGSTval);
\$(this).parent().nextAll().eq(4).find("input[id*='TIGST']").val("0");
var TotalAmount = AmountAfterDiscount + SGSTCGSTval * 2;

\$(this).parent().nextAll().eq(5).find("input[id*='TTotal']").val(TotalAmount);
//Item Total Amount
var id = \$(this).parent().nextAll().eq(5).find("input[id*='TTotal']").attr('id');
var spitid = id.split('_');
var intidindex = parseInt(spitid[2])
if (intidindex == 0) {
\$("input[id\$='AmountTotal']").val(TotalAmount);
\$("input[id\$='GT']").val(TotalAmount);
}
else {
for (var i = intidindex - 1; i >= 0; i--) {
var pretotal = \$(this).parent().parent().prevAll().eq(i).find("input[id*='TTotal']").val();
TotalAmount += parseFloat(pretotal);
\$("input[id\$='AmountTotal']").val(TotalAmount);
\$("input[id\$='GT']").val(TotalAmount);
}
}
}
if (TaxFormatval == "IGST") {
var Tax = \$(this).parent().prevAll().eq(5).find("span[id*='LTax']").text()
var taxdividebytwo = parseFloat(Tax) / 100;
var IGSTval = AmountAfterDiscount * taxdividebytwo;
\$(this).parent().nextAll().eq(2).find("input[id*='TCGST']").val("0");
\$(this).parent().nextAll().eq(3).find("input[id*='TSGST']").val("0");
//1. IGST set 10%  it ahs to show 284.85
//\$(this).parent().nextAll().eq(4).find("input[id*='TIGST']").val(IGSTval.toPrecision(3));
\$(this).parent().nextAll().eq(4).find("input[id*='TIGST']").val(IGSTval.toPrecision(4));
var TotalAmount = AmountAfterDiscount + IGSTval;
\$(this).parent().nextAll().eq(5).find("input[id*='TTotal']").val(TotalAmount);
//Item Total Amount
var id = \$(this).parent().nextAll().eq(5).find("input[id*='TTotal']").attr('id');
var spitid = id.split('_');
var intidindex = parseInt(spitid[2])
for (var i = intidindex - 1; i >= 0; i--) {
var pretotal = \$(this).parent().parent().prevAll().eq(i).find("input[id*='TTotal']").val();
TotalAmount += parseFloat(pretotal);
\$("input[id\$='AmountTotal']").val(TotalAmount);
\$("input[id\$='GT']").val(TotalAmount);
}
}
}
})
})
})
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" Width="700" ShowFooter="true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" Height="20px" Width="20px" CssClass="chkSelect" onclick="CheckSelected_Click(this)" />
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Ref No" SortExpression="DC_ Ref No">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Ref_No") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="130px" />
</asp:TemplateField>

<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Arrival_Date", "{0:dd-MMM-yyyy}") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="95px" />
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Item_Name") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="200px" />
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LHSN" runat="server" Text='<%# Bind("HSN_Code") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="200px" />
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LTaxFormat" runat="server" Text='<%# Bind("Tax_Format") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="200px" />
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LTax" runat="server" Text='<%# Bind("Tax_Perc") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="20px" />
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LPack" runat="server" Text='<%# Bind("Packing") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="100px" />
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Rate") %>' contentEditable="false" ValidationGroup="a" Width="40px" Font-Bold="True" Font-Size="10pt"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("UOM") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="LTQ" runat="server" Width="70px" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="14pt" ForeColor="Purple"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LItemAmount" runat="server"></asp:Label>
<asp:TextBox ID="LCA" runat="server" contentEditable="false" Width="80px"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TDPerc" runat="server" Width="70px" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="14pt" ForeColor="Purple"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TDAmt" runat="server" Width="70px" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="14pt" ForeColor="Purple"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TAmtAfterDis" runat="server" Width="70px" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="14pt" ForeColor="Purple"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TCGST" runat="server" Width="70px" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="14pt" ForeColor="Purple"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TSGST" runat="server" Width="70px" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="14pt" ForeColor="Purple"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TIGST" runat="server" Width="70px" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="14pt" ForeColor="Purple"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TTotal" ClientIDMode="Static" runat="server" Width="70px" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="14pt" ForeColor="Purple"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<table>
<tr>
<td style="width: 100px; height: 20px; text-align: left">
<span style="color: blue">Item Total Amount</span></td>
<td style="width: 100px; height: 20px">
<asp:TextBox ID="AmountTotal" runat="server" contentEditable="false" Font-Bold="True" ForeColor="Blue"
Width="80px" Font-Names="Palatino Linotype" Font-Size="10pt"></asp:TextBox></td>
<td style="width: 100px; height: 20px"></td>
</tr>
<tr>
<td style="width: 100px; height: 20px; text-align: left">Forwarding</td>
<td style="width: 100px; height: 20px">
<asp:TextBox ID="Famt" runat="server" CssClass="textSelector" ValidationGroup="a" Width="80px"></asp:TextBox></td>
<td style="width: 100px; height: 20px"></td>
</tr>
<tr>
<td style="width: 100px; height: 20px; text-align: left;">Packing</td>
<td style="width: 100px; height: 20px;">
<asp:TextBox ID="Pack" runat="server" CssClass="textSelector" ValidationGroup="a" Width="80px"></asp:TextBox></td>
<td style="width: 100px; height: 20px;"></td>
</tr>
<tr>
<td style="width: 100px; height: 26px; text-align: center">Forwarding + Packing Tax</td>
<td style="width: 100px; height: 26px">
<asp:TextBox ID="TextBox4" runat="server" CssClass="textSelector" ValidationGroup="a"
Width="80px"></asp:TextBox></td>
<td style="width: 100px; height: 26px">
<asp:DropDownList
ID="D1" runat="server" CssClass="textSelector">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>5% Tax</asp:ListItem>
<asp:ListItem>10% Tax</asp:ListItem>
<asp:ListItem>20% Tax</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td style="width: 100px; text-align: left; height: 24px;">MIS</td>
<td style="width: 100px; height: 24px;">
<asp:TextBox ID="MIS" runat="server" CssClass="textSelector" ValidationGroup="a" Width="80px"></asp:TextBox></td>
<td style="width: 100px; height: 24px;"></td>
</tr>
<tr>
<td style="width: 100px; text-align: left">Round Off</td>
<td style="width: 100px">
<asp:TextBox ID="Roff" runat="server" CssClass="textSelector" ValidationGroup="a" Width="80px"></asp:TextBox></td>
<td style="width: 100px"></td>
</tr>
<tr>
<td style="width: 100px; text-align: left">
<span style="font-size: 14pt; color: mediumseagreen">G.Total</span></td>
<td style="width: 100px">
<asp:TextBox ID="GT" runat="server" contentEditable="false" Font-Names="Palatino Linotype" Width="80px" Font-Size="10pt" Style="vertical-align: middle; text-align: right"
ForeColor="Black"></asp:TextBox></td>
<td style="width: 100px"></td>
</tr>
<tr>
<td style="width: 100px; text-align: left">Item Amount Total</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox2" runat="server" CssClass="textSelector" ValidationGroup="a" Width="80px"></asp:TextBox>
</td>
<td style="width: 100px">
</tr>
<tr>
<td style="width: 100px; text-align: left">DisCount Amount Total</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox3" runat="server" CssClass="textSelector" ValidationGroup="a" Width="80px"></asp:TextBox>
</td>
<td style="width: 100px">
</tr>
</table>
</FooterTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="LBatchNo" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>```
```protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
new DataColumn("Arrival_Date", typeof(string )),
new DataColumn("Item_Name",typeof(string)),
new DataColumn("HSN_Code",typeof(string)),
new DataColumn("Tax_Format",typeof(string)),
new DataColumn("Tax_Perc",typeof(string)),
new DataColumn("Packing",typeof(string)),
new DataColumn("Rate",typeof(string)),
new DataColumn("UOM",typeof(string)),
});
dt.Rows.Add("R12", "1-Jun-17", "Apple", "123", "CGST+SGST", "18%", "Seal", "10", "Kg");
dt.Rows.Add("R12", "1-Jun-17", "Mango", "345", "CGST+SGST", "28%", "Seal", "20", "Kg");
dt.Rows.Add("R34", "1-Jun-17", "Lemon", "678", "IGST", "18%", "Seal", "5", "Kg");
dt.Rows.Add("R34", "1-Jun-17", "Banana", "874", "CGST+SGST", "18%", "Seal", "10", "Kg");
GridView2.DataSource = dt;
GridView2.DataBind();
}```

Result:

Best Regards,

Eric Du

MSDN Community Support