通过DataBinder.Eval方法我们可以获得DataRow中的数据,并对其求和即可
在gridview的RowDataBound()事件中:
if e.Row.RowType=DataControlRowType.DataRow then
priceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem,”thisPrice”))
quantityTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,”quantity”))
elseif e.Row.RowType = DataControlRowType.Footer then
e.Row.Cells(0).Text = “Totals”
e.Row.Cells(1).Text=priceTotal.ToString(“c”)
e.Row.Cell(2).Text=quantityTotal.ToString(“d”)
e.Row.Cell(1).HorigontalAlign = HorigontalAlign.Right
e.Row.Cell(2).HorigontalAlign = HorigontalAlign.Right
e.Row.Font.Bold = True
end if