如何计算Gridview中字段的总和 [英] How to calculate the sum of the fields in Gridview
本文介绍了如何计算Gridview中字段的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有
我正在尝试计算gridview中字段的总和我有以下代码请修改它。
Dear All
I am trying to calculate the sum of the fields in gridview I have the following code below please modify it.
protected void btnSave_Click(object sender, EventArgs e)
{
ResultDbEntities rd = new ResultDbEntities();
tblPE1 pe1 = new tblPE1();
rd.tblPE1.Add(new tblPE1() { StID = int.Parse(txtID.Text), SName = txtName.Text, FName = txtFName.Text, Group = txtGroup.Text,English=int.Parse(txtEng.Text), Physics=int.Parse(txtPhy1.Text), Chemistry=int.Parse(txtChem1.Text),Math=int.Parse(txtMath.Text),term=txtTerm.Text,});
rd.SaveChanges();
var res = re.tblPE1.ToList();
GridView1.DataSource = res.ToList();
GridView1.DataBind();
}
推荐答案
不知道到底在找什么,
但我明白了,如果它正确的话请查看下面的代码
Not sure what exactly you are looking for ,
but what i understood if its correct then look for below code
decimal total = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (!row.IsNewRow && row.Cells["Total"].Value != null)
{
total += (decimal)row.Cells["Total"].Value;
}
}
label1.Text = total.ToString("N2");
你实际可以获得总价值
you can actually get the value of total
http://www.c-sharpcorner.com/UploadFile/rohatash/adding-values-in-column-and-sum-of-the-column-values-in-grid/ [ ^ ]
这篇关于如何计算Gridview中字段的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文