有时Total值可能为null,因此如果Total为null,我会尝试将其替换为零。我有这段代码:
decimal total = dt.AsEnumerable().Sum(row => row.Field<decimal?>("Remaining_Ballance")??0);
GridView1.FooterRow.Cells[11].Text = "Total";
GridView1.FooterRow.Cells[11].HorizontalAlign = HorizontalAlign.Right;
GridView1.FooterRow.Cells[12].Text = total.ToString("N2");
我收到此错误:
对象引用未设置为对象的实例。
并且在第二行失败
GridView1.FooterRow.Cells[11].Text = "Total";