Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i get the sum of label with jquery in grid view
i m having text box , with another column as label and need to display sum of total in footer when text box will be change
my text box total is working fine on text box change event, but total of label not working, as i don't know which event will be used when label text will be change

What I have tried:

$("[id*=GvList] [id*=labelValue]").on("change", function ()
{
var total = 0;
$($("[id*=GvList] [id*=labelValue]")).each(function ()
{
if (!isNaN(parseInt($(this).val()))) {
total += parseInt($(this).val());
}
});
$("[id*=GvList] [id*=lbl_PY_total]").html(total);
}
);
Posted
Updated 16-May-19 5:58am

The label element doesn't have an onchange event because it's intended to display read-only content. You need to wire-up the onchange event on the TextBox element instead and then do the computation logic there, and finally display the result to your label. Here's one article that may help you get started: How To: Do Calculations in GridView[^]
 
Share this answer
 
function Calctotal_pre(PreviousValue, txtvalue, TotalValue)
{
var uservalue = parseFloat(document.getElementById(txtvalue).value);
var TotalVar = document.getElementById(TotalValue);

var TotalValue = parseFloat(PreviousValue + uservalue );
TotalVar.innerHTML = TotalValue;

var total_allPY = 0;
$($("[id*=GvList] [id*=lbl_sum]")).each(function ()
{
if (!isNaN(parseFloat($(this).val())))
{
total_allPY += parseFloat($(this).val());
}
});

$("[id*=GvList] [id*=lbl_PY_total]").html(total_allPY);
}


----------------CODE PART--------------

protected void GvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblList = (Label)e.Row.FindControl("lbl_pre");
PreVal += Convert.ToDecimal(lblList.Text);

txt_pre.Attributes.Add("onkeyup", "Calctotal_pre(" + PreVal + ", '" + txtqut.ClientID + "','" + lbl_sum.ClientID + "')");
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900