对gridview页面数据求和

通过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

posted @ 2009-06-04 21:33  斑点海豚---寂静的港湾  阅读(202)  评论(0)    收藏  举报