Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All

I am trying to calculate the sum of the fields in gridview I have the following code below please modify it.
C#
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();
}
Posted
v3
Comments
Not clear. What is the issue here?

Not sure what exactly you are looking for ,

but what i understood if its correct then look for below code

C#
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
 
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