Groups | Blog | Home
all groups > asp.net > february 2004 >

asp.net : Add a Row to DataGrid


Jon
2/16/2004 11:41:51 PM
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

Jon
2/17/2004 12:00:32 AM
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

[quoted text, click to view]

Andrew de la Harpe
2/17/2004 10:50:20 AM
Insert the total into the footer
A
[quoted text, click to view]

AddThis Social Bookmark Button