I want to calculate in first Step as following
Recievable + Arrears -Discount = NetBal
1000 + 250 - 250 = 1000
Then
NetBal - Paid = RemBal
1000 - 700 = 700
<script>
$(function () {
$(".field1").keyup(function () {
var total = 0;
$(".field1").each(function () {
total += parseFloat($(this).val());
});
$(".totaloffield td").eq(1).text(total);
//calculate total for current row
var val1 = $(this).val();
var val2 = $(this).parent().parent().find(".field2").val();
var val3 = $(this).parent().parent().find(".field3").val();
var rowtotal = parseFloat(val1) + parseFloat(val2) - parseFloat(val3);
$(this).parent().siblings().last().text(rowtotal);
});
$(".field2").keyup(function () {
var total = 0;
$(".field2").each(function () {
total += parseFloat($(this).val());
});
$(".totaloffield td").eq(2).text(total);
//calculate total for current row
var val1 = $(this).parent().parent().find(".field1").val();
var val2 = $(this).val();
var val3 = $(this).parent().parent().find(".field3").val();
var rowtotal = parseFloat(val1) + parseFloat(val2) - parseFloat(val3);
$(this).parent().siblings().last().text(rowtotal);
});
$(".field3").keyup(function () {
var total = 0;
$(".field3").each(function () {
total += parseFloat($(this).val());
});
$(".totaloffield td").eq(3).text(total);
//calculate total for current row
var val1 = $(this).parent().parent().find(".field1").val();
var val2 = $(this).parent().parent().find(".field2").val();
var val3 = $(this).val();
var rowtotal = parseFloat(val1) + parseFloat(val2) - parseFloat(val3);
$(this).parent().siblings().last().text(rowtotal);
});
})
</script>
<asp:GridView ID="gvBudget" runat="server" AutoGenerateColumns="False"
Width="100%" Class="table table-striped table-bordered table-hover"
PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
ShowFooter="True">
<Columns>
<asp:BoundField DataField="AdmissionNo" HeaderText="AdmissionNo">
<HeaderStyle HorizontalAlign="Left" Width="10%" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="10%" />
</asp:BoundField>
<asp:TemplateField HeaderText="Recievable">
<ItemTemplate>
<asp:TextBox ID="txtReci" runat="server" Text='<%# Bind("Recievable") %>'
Width="100%" class="field1 form-control" autocomplete="off">
</asp:TextBox>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="10%" />
<ItemStyle HorizontalAlign="Left" Width="10%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Arrears">
<ItemTemplate>
<asp:TextBox ID="txtArr" runat="server" Text='<%# Bind("Arrears") %>'
Width="100%" class="field2 form-control" autocomplete="off">
</asp:TextBox>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="10%" />
<ItemStyle HorizontalAlign="Left" Width="10%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Discount">
<ItemTemplate>
<asp:TextBox ID="txtDis" runat="server" Text='<%# Bind("CDiscount") %>'
Width="100%" class="field3 form-control" autocomplete="off">
</asp:TextBox>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="10%" />
<ItemStyle HorizontalAlign="Left" Width="10%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Net Balance">
<ItemTemplate>
<asp:TextBox ID="txtNet" runat="server" Text='<%# Bind("NetBal") %>'
Width="100%" class="field4 form-control" autocomplete="off">
</asp:TextBox>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="10%" />
<ItemStyle HorizontalAlign="Left" Width="10%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Paid">
<ItemTemplate>
<asp:TextBox ID="txtPaid" runat="server" Text='<%# Bind("Paid") %>'
Width="100%" class="field5 form-control" autocomplete="off">
</asp:TextBox>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="10%" />
<ItemStyle HorizontalAlign="Left" Width="10%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Rem Bal">
<ItemTemplate>
<asp:TextBox ID="txtRem" runat="server" Text='<%# Bind("RemBal") %>'
Width="100%" class="field6 form-control" autocomplete="off">
</asp:TextBox>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="10%" />
<ItemStyle HorizontalAlign="Left" Width="10%" />
</asp:TemplateField>
<asp:BoundField HeaderText="Total" />
</Columns>
<FooterStyle Font-Bold="True" CssClass="totaloffield" />
</asp:GridView>
protected void BindGrid()
{
con = new SqlDbConnect();
//con.SqlQuery("select * from ( select g.AdmissionNo,Recievable,CDiscount,Arrears,sum(Head+AdmFees+TutionFees+LibFees+ExamFees+SportsFees+AnnualFees+ProspectusFees+UniformFees+BookFees+TokenFees+IDCardFees+BusCardFees+ElecFees+SchoolFund+FunFees+CSFees+GeneratorFees+SecFees+TourFees+Others) as [NetBal],c.Paid,RemBal,g.Month,c.VoucherNo from tblFeesGenerate g left outer join tblFeesCollection c on g.AdmissionNo=c.AdmissionNo and g.Month=c.FeesMonth inner join tblStdReg as sr on g.AdmissionNo=sr.AdmissionNo and Active_Status='Active' where Year=@Year and Month=@Month group by g.AdmissionNo,Month,VoucherNo,Paid,CDiscount,Arrears,Recievable,RemBal) tb where VoucherNo is null order by Month;");
con.SqlQuery("select * from (select g.AdmissionNo,SName,sum(Head+AdmFees+TutionFees+LibFees+ExamFees+SportsFees+AnnualFees+ProspectusFees+UniformFees+BookFees+TokenFees+IDCardFees+BusCardFees+ElecFees+SchoolFund+FunFees+CSFees+GeneratorFees+SecFees+TourFees+Others) as [Recievable],c.CDiscount,c.Arrears,c.NetBal,c.Paid,c.RemBal,c.VoucherNo from tblFeesGenerate g left outer join tblFeesCollection c on g.AdmissionNo=c.AdmissionNo and g.Month=c.FeesMonth inner join tblStdReg as sr on g.AdmissionNo=sr.AdmissionNo where Year=@Year and Month=@Month group by g.AdmissionNo,SName,VoucherNo,Recievable,Arrears,CDiscount,NetBal,Paid,RemBal) tb where VoucherNo is null;");
con.Cmd.Parameters.Add(new SqlParameter("@Year", ddlFYear.SelectedItem.ToString()));
con.Cmd.Parameters.Add(new SqlParameter("@Month", ddlMonth.SelectedItem.ToString()));
adapt.SelectCommand = con.Cmd;
adapt.Fill(sTable);
if (sTable.Rows.Count > 0)
{
gvBudget.Visible = true;
gvBudget.DataSource = sTable;
gvBudget.DataBind();
lblTotal.Text = gvBudget.Rows.Count.ToString();
}
else
{
gvBudget.Visible = false;
Response.Write("No Record Found");
lblTotal.Text = "0";
return;
}
con.conClose();
}