Display sum of column in table footer

Last Reply 13 days ago By PrinceG

Posted 16 days ago

Hi

  I want to display SUm of AMount in table Footer. It should appear below Amount column

 

 

Hi
 
   Below code is not working
 
private void GetData()

{

try

{

PRDataContext context = new PRDataContext();

StringBuilder htmlTable = new StringBuilder();

Int32 rownum = 0;

var Result = (from t in context.View_Entries

where t. Code == Convert.ToInt32(hdfCode.Value)

select t);

if (Result != null)

{

htmlTable.Append("<table class='table table-striped table-hover dataTable table-bordered' data-provide='data-table' id='tbldata'>");

htmlTable.Append("<thead><tr><th>#</th><th>Year</th<th style='text-align:right'>Budget Amount</th</tr></thead>");

htmlTable.Append("<tbody>");

foreach (var colum in Result)

{

rownum++;

htmlTable.Append("<tr>");

htmlTable.Append("<td class='ID'>" + rownum + " <span style='display:none'>" + colum.ID + "</span></td>");

htmlTable.Append("<td>" + colum. Year + "</td>");

htmlTable.Append("<td style='text-align:right'>" + Convert.ToDecimal(colum. Amount).ToString("0,0", System.Globalization.CultureInfo.CreateSpecificCulture("hi-IN")) + "</td>");

htmlTable.Append("</tr>");

}

htmlTable.Append("</tbody>");

htmlTable.Append("</tfooter>").Append("</tr>").Append("</td id='total'>");

htmlTable.Append("</table>");

PlaceHolder1.Controls.Add(new Literal { Text = htmlTable.ToString() });

}

}

catch (Exception ex)

{

SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name);

MessageBox.Show(ex.Message);

}

}

 
$(function(){
var tds = $("#tblData tbody").find("td");
var sum = 0;
$(tds).each(function () {
sum = sum + parseFloat($(this).eq(9).text());
alert(sum);
});

alert(sum);
$("#total").html(sum);
})
 
Thanks 

 

The reply you are looking for seems to be deleted or does not exist.