datagridview 行合计的问题
protected void grid1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (grid1.CurrentCell.OwningColumn.Name == "cpjj")
{
if (grid1.CurrentRow .Cells [12].ToString () != "" && grid1.CurrentRow .Cells[14].Value.ToString() != "")
{
grid1.CurrentRow .Cells[15].Value = decimal.Parse(grid1.CurrentRow .Cells[12].Value.ToString()) * decimal.Parse(grid1.CurrentRow .Cells[14].Value.ToString());
gethj();//合计方法
}
}
}
protected void gethj()
{
decimal hj = 0;
int i;
for(i=0;i<=table .Rows .Count-1 ;i++)
{
if (table .Rows [i]["gjje"].ToString() != "")
{
hj += decimal.Parse(table.Rows[i]["gjje"].ToString());
}
}
txt5.Text = hj.ToString();
txt6.Text = hj.ToString();
}
合计总是少一行,(如有一合,txt5的值为零,如有两行txt5的值只有一行的值)这是什么原因?
------解决方案--------------------
那是不是
C# code
if (table .Rows [i]["gjje"].ToString() != "")