how I can show the sum of in a datagridview column in asp.net

后端 未结 2 1651
无人及你
无人及你 2021-01-23 10:29

i have a datagridview which are used to display a transaction record. And one of the columns in datagridview is \"amount\"

girdview codeenter code here

2条回答
  •  -上瘾入骨i
    2021-01-23 11:04

    try this...

     int sum = 0;
     for (int i = 0; i < dataGridView1.Rows.Count; ++i)
     {
         sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
     }
    GridViewRow row = GridView1.FooterRow; 
    ((Label)row.FindControl("lbltotal")).Text=sum.ToString();
    

提交回复
热议问题