Skip to content
Loading
+1
  • Sachin Singh
    +1
    Brother, you have to put it in ready function, otherwise who will call it?
     
    1. $(function(){  
    2. var tds=$("#tblData tbody").find("td");    
    3. var sum=0;    
    4. $(tds).each(function(){    
    5. sum=sum+parseInt($(this).eq(3).text());    
    6. });    
    7.     
    8. $("#total").html(sum);    
    9. })  
    +1
  • Sachin Singh
    +1
    better write the code just after where you are creating the table, i think you are creating table in Ajax success, so write the code in success only, after the table creation.
    +1
  • +1
    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("

    ");

    htmlTable.Append("

    ");

    htmlTable.Append("

    ");

    foreach (var colum in Result)

    {

    rownum++;

    htmlTable.Append("

    ");

    htmlTable.Append("

    ");

    htmlTable.Append("

    ");

    htmlTable.Append("

    ");

    htmlTable.Append("

    ");

    }

    htmlTable.Append("

    ");

    htmlTable.Append("").Append("").Append("");

    htmlTable.Append("

    #YearBudget Amount
    " + rownum + " " + colum.ID + " " + colum. Year + " " + Convert.ToDecimal(colum. Amount).ToString("0,0", System.Globalization.CultureInfo.CreateSpecificCulture("hi-IN")) + "
    ");

    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 
    +1
  • Sachin Singh
    +1
    what is the error, put a debugger and inspect in console, is the eq(3).text() giving the budget amount or not?
    +1