DataFormatString not working in GridView

Discussion in 'ASP .Net' started by Alan Silver, Feb 20, 2006.

  1. Alan Silver

    Alan Silver Guest

    Hello,

    I have a GridView control, and am unsuccessfully trying to format a
    column to show costs. The (simplified) code is as follows...

    <asp:GridView ID="grdCustomers" DataSourceID="dtaCustomers"
    AutoGenerateColumns="false" runat="server">
    <Columns>
    <asp:BoundField DataField="Total" DataFormatString="&pound;{0:F2}" />
    </Columns>
    </asp:GridView>

    As you can see, I have set the DataFormatString to "&pound;{0:F2}",
    which should give them a Pound sign, followed by the value with two
    decimal places (like you would expect a cost to look).

    The problem is that the numbers are not being formatted correctly. I
    have things like $23.9 (where I have changed the pound sign to a dollar
    sign to ensure it shows up right in Usenet). This should show as $23.90,
    with the extra zero.

    Any ideas? TIA


    --
    Alan Silver
    (anything added below this line is nothing to do with me)
     
    Alan Silver, Feb 20, 2006
    #1
    1. Advertising

  2. Alan Silver

    Darren Kopp Guest

    Darren Kopp, Feb 20, 2006
    #2
    1. Advertising

  3. Alan Silver

    Alan Silver Guest

    In article <>,
    Darren Kopp <> writes
    >try DataFormatString = &pound; {0:0.00}, but what you have should
    >work...


    Thanks for the suggestion, but that didn't work either.

    It worries me when you say what I have should work!! Is there anything
    else I can check to see why it isn't. Thanks again

    --
    Alan Silver
    (anything added below this line is nothing to do with me)
     
    Alan Silver, Feb 20, 2006
    #3
  4. Alan Silver

    Darren Kopp Guest

    And you said that {0:c} gave you $23.90 right?
     
    Darren Kopp, Feb 21, 2006
    #4
  5. Alan Silver

    Alan Silver Guest

    In article <>,
    Darren Kopp <> writes
    >And you said that {0:c} gave you $23.90 right?


    No, it gave $23.9

    --
    Alan Silver
    (anything added below this line is nothing to do with me)
     
    Alan Silver, Feb 21, 2006
    #5
  6. Alan Silver

    Darren Kopp Guest

    What is the datatype of "Total" (.NET data type or Database data type)

    -Darren
     
    Darren Kopp, Feb 21, 2006
    #6
  7. Alan Silver

    Darren Kopp Guest

    What is the datatype of "Total" (.NET data type or Database data type)

    -Darren
     
    Darren Kopp, Feb 21, 2006
    #7
  8. Alan Silver

    Alan Silver Guest

    In article <>,
    Darren Kopp <> writes
    >What is the datatype of "Total" (.NET data type or Database data type)


    It's a computed field that comes from an SQL expression like...

    select sum(priceeach*quantity) from siteorders...

    where "priceeach" is a float and "quantity" is an int.

    Thanks

    --
    Alan Silver
    (anything added below this line is nothing to do with me)
     
    Alan Silver, Feb 22, 2006
    #8
  9. Alan Silver

    Darren Kopp Guest

    Darren Kopp, Feb 23, 2006
    #9
  10. Alan Silver

    Teemu Keiski Guest

    Teemu Keiski, Feb 23, 2006
    #10
  11. Alan Silver

    Alan Silver Guest

    Ah ha! That fixed it. Thanks for the reply.

    In article <#>, Teemu Keiski
    <> writes
    >That's the solution. here's also an explanation:
    >
    >GridView & DataFormatString in post beta 2
    >http://aspadvice.com/blogs/joteke/archive/2005/09/25/12871.aspx
    >


    --
    Alan Silver
    (anything added below this line is nothing to do with me)
     
    Alan Silver, Feb 23, 2006
    #11
  12. Alan Silver

    Darren Kopp Guest

    Darren Kopp, Feb 23, 2006
    #12
  13. Chop Hofilena, Mar 10, 2006
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gerhard Pretorius

    August CTP DataFormatString in Gridview not working

    Gerhard Pretorius, Sep 6, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,706
    Louis
    Sep 22, 2005
  2. ThunderMusic
    Replies:
    4
    Views:
    4,732
    ThunderMusic
    Jan 27, 2006
  3. Rob Roberts
    Replies:
    3
    Views:
    22,201
    Martin Arredondo
    Apr 13, 2007
  4. Replies:
    1
    Views:
    1,884
    Ken Cox [Microsoft MVP]
    Aug 24, 2006
  5. Aaron

    DataFormatString on boundcolumn not working

    Aaron, Apr 15, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    300
    Michael Tkachev
    Apr 16, 2004
Loading...

Share This Page