Add a Row to DataGrid

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

Hi,
Working on a shopping cart app. I'm using a datagrid on the shopping cart
page with boundcolumns to display Product name, cost, quantity etc - that
all works fine. However I want to add a row to the bottom of the grid to
display cart total, so I'd end up with something like this
Product Cost Quantity Sub Total
Product1 10.22 1 10.22
Product2 5.00 2 10.00
Cart Total 20.22

So my question is how do I add a row to the bottom of the datagrid to
display the total?

Cheers,
Jon
 
I needed to calculate the total first :-)..... Anyway got it
<asp:DataGrid OnItemDataBound="CalculateTotal"....

Sub CalculateTotal(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Then
Dim Count As Decimal = Convert.ToDecimal(DataBinder.Eval(e.Item.DataItem,
"ItemTotal"))
Total += Count
ElseIf e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells(6).Text = String.Format("{0:c}", Total)
End If
End Sub

Cheers,
Jon
 
Back
Top