Hi,
Within an e-commerce based web site, I display contents of the
shopping cart. Within the cart there are the following fields :
Quantity
ItemPrice (Look up within database)
Amount = Quantity x ItemPrice
However the cart only displays the amount as a decimal e.g. 8.00 and I
would like this value to be displayed using a £ sign i.e. £8.00. How
can I build this into the code ?
Here's the code for the datagrid whjich is the shopping cart :
Code:
<asp:DataGrid id="dgCart" runat="server"
OnUpdateCommand="dgCart_Update" OnEditCommand="dgCart_Edit"
OnCancelCommand="dgCart_Cancel" OnDeleteCommand="dgCart_Delete"
AutoGenerateColumns="False" DataKeyField="intCartitemID"
ShowFooter="True" OnItemDataBound="ComputeSum"
HorizontalAlign="Center">
<FooterStyle horizontalalign="Center" forecolor="Blue"
backcolor="#E2E2E2"></FooterStyle>
<HeaderStyle horizontalalign="Center" forecolor="Red"
backcolor="#E2E2E2"></HeaderStyle>
<AlternatingItemStyle forecolor="Navy"
backcolor="#FFFFD5"></AlternatingItemStyle>
<ItemStyle forecolor="Black" backcolor="White"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="intProductID" ReadOnly="True"
HeaderText="ProductID">
<HeaderStyle horizontalalign="Center"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="strMake" ReadOnly="True"
HeaderText="Make">
<HeaderStyle horizontalalign="Center"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="strProductName" ReadOnly="True"
HeaderText="Model">
<HeaderStyle wrap="False"
horizontalalign="Center"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="strTypeDetails" ReadOnly="True"
HeaderText="Product Type">
<HeaderStyle wrap="False"
horizontalalign="Center"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="strColour" ReadOnly="True"
HeaderText="Colour">
<HeaderStyle horizontalalign="Center"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<HeaderStyle horizontalalign="Center"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.intQuantityOrder") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtQuantity" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.intQuantityOrder")
%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="curSalePrice" ReadOnly="True"
HeaderText="Item Price" DataFormatString="#163;{0:F2}">
<HeaderStyle wrap="False"
horizontalalign="Center"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Amount">
<HeaderStyle wrap="False"
horizontalalign="Center"></HeaderStyle>
<ItemStyle wrap="False" horizontalalign="Center"></ItemStyle>
<ItemTemplate>
<%# FormatNumber(GetAmount(Container.DataItem("curSalePrice"),
Container.DataItem("intQuantityOrder"))) %>
</ItemTemplate>
<FooterStyle wrap="False"></FooterStyle>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit Quantity">
<HeaderStyle wrap="False"
horizontalalign="Center"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>
<FooterStyle wrap="False"></FooterStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete">
<HeaderStyle wrap="False"
horizontalalign="Center"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>
<FooterStyle wrap="False"></FooterStyle>
</asp:ButtonColumn>
</Columns>
</asp:DataGrid>
Here's the code that calculates the "Amount" value :
Code:
'Computes sum sub procedure
Sub ComputeSum(sender As Object, e As DataGridItemEventArgs)
'Ensure dealing with an Item or AlternatingItem
If e.Item.ItemType = ListItemType.Item OR _
e.Item.ItemType = ListItemType.AlternatingItem then
'Define the ViewCount
Dim viewCount as Integer = Amount
viewCountSum += viewCount
'Otherwise display total info in footer
ElseIf e.Item.ItemType = ListItemType.Footer then
e.Item.Cells(7).Text = "Total: £" &
String.Format("{0:F2}", viewCountSum)
End If
End Sub
'Function to produce amount value
Function GetAmount(curSalePrice As Decimal, intQuantity As
Decimal)
'Amount equals the sale price multiplied by its quantity
Amount = curSalePrice * intQuantity
'Total = "£" & Amount
'Total =+ Amount
Total.Text = "£" & String.Format("{0:F2}", Amount)
'Returns amount value
Return Amount
End Function
'Function to produce Total value
Function GetTotal()
Return Total
End Function
The code used here is asp.net 1.1 with
vb.net and connected to an
access database.
Thanks,