Friday 18 January 2008

Adding Total Columns to GridView Footer

Here's an example of how to add a total to a GridViews' footer. Let's say we have a function which gives the total value of sales of a given product, which receives a single paramater of productID.


Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As _ System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then

ElseIf e.Row.RowType = DataControlRowType.Footer Then

e.Row.Cells(2).Text = "TOTAL : "
e.Row.Cells(3).Text = GetTotal(request.querystring("productID"))

End If

End Sub

No comments: