Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2007, 04:49 AM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formatting Query

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,



 
Old May 19th, 2007, 04:58 AM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got it working now thanks.

Just changed the following line from :

<%# FormatNumber(GetAmount(Container.DataItem("curSale Price"),

TO

<%# FormatCurrency(GetAmount(Container.DataItem("curSa lePrice"),







Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Query rsm42 ASP.NET 1.0 and 1.1 Basics 0 December 21st, 2006 02:47 PM
Formatting sql query rows as columns with stack sastian PHP Databases 0 March 25th, 2005 04:51 AM
Query/formatting problem in report mega Access VBA 8 September 16th, 2004 04:29 AM
MYSQL Query text Formatting yourcompadre Beginning PHP 1 May 12th, 2004 06:55 AM
Formatting Ben Access 3 February 28th, 2004 05:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.