Number formatting in a datagrid

Discussion in 'ASP .Net' started by =?Utf-8?B?SnVsaWEgQg==?=, Sep 4, 2007.

  1. Hi all

    I've got a datagrid with column with the numeric format {0:F2}. However this
    format expression does not give the numbers comma separators, which I need. I
    can't use the currency format, because I've got multiple currencies and
    currency format automatically picks up your local currency.

    I've searched everywhere for examples and can't find what I need. Has anyone
    got any help they could give me please?

    Thanks
     
    =?Utf-8?B?SnVsaWEgQg==?=, Sep 4, 2007
    #1
    1. Advertising

  2. "Julia B" <> wrote in message
    news:...
    > Hi all
    >
    > I've got a datagrid with column with the numeric format {0:F2}. However
    > this
    > format expression does not give the numbers comma separators, which I
    > need. I
    > can't use the currency format, because I've got multiple currencies and
    > currency format automatically picks up your local currency.
    >
    > I've searched everywhere for examples and can't find what I need. Has
    > anyone
    > got any help they could give me please?


    <asp:BoundField DataField="MyField" DataFormatString="{0:#0.00}"
    HtmlEncode="false" />


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Sep 4, 2007
    #2
    1. Advertising

  3. Thanks, much appreciated!

    "Mark Rae [MVP]" wrote:

    > "Julia B" <> wrote in message
    > news:...
    > > Hi all
    > >
    > > I've got a datagrid with column with the numeric format {0:F2}. However
    > > this
    > > format expression does not give the numbers comma separators, which I
    > > need. I
    > > can't use the currency format, because I've got multiple currencies and
    > > currency format automatically picks up your local currency.
    > >
    > > I've searched everywhere for examples and can't find what I need. Has
    > > anyone
    > > got any help they could give me please?

    >
    > <asp:BoundField DataField="MyField" DataFormatString="{0:#0.00}"
    > HtmlEncode="false" />
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
     
    =?Utf-8?B?SnVsaWEgQg==?=, Sep 4, 2007
    #3
  4. Hi Mark

    Sorry to be a pain, I've emailed thanks and said that your post answered my
    question, but I've hit a problem. I changed the dataformat string, but it's
    being ignored. I assume it's because I need the HtmlEncode="false", which
    I've tried adding to a bound column but I can't. I get an error that
    htmlencode can't be found as an attribute of a bound column.

    I should say I'm using .net 1.1.

    Any ideas?

    Thanks
    "Mark Rae [MVP]" wrote:

    > "Julia B" <> wrote in message
    > news:...
    > > Hi all
    > >
    > > I've got a datagrid with column with the numeric format {0:F2}. However
    > > this
    > > format expression does not give the numbers comma separators, which I
    > > need. I
    > > can't use the currency format, because I've got multiple currencies and
    > > currency format automatically picks up your local currency.
    > >
    > > I've searched everywhere for examples and can't find what I need. Has
    > > anyone
    > > got any help they could give me please?

    >
    > <asp:BoundField DataField="MyField" DataFormatString="{0:#0.00}"
    > HtmlEncode="false" />
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
     
    =?Utf-8?B?SnVsaWEgQg==?=, Sep 4, 2007
    #4
  5. "Julia B" <> wrote in message
    news:...

    > Sorry to be a pain, I've emailed thanks and said that your post answered
    > my
    > question, but I've hit a problem. I changed the dataformat string, but
    > it's
    > being ignored. I assume it's because I need the HtmlEncode="false", which
    > I've tried adding to a bound column but I can't. I get an error that
    > htmlencode can't be found as an attribute of a bound column.
    >
    > I should say I'm using .net 1.1.


    Always helps to say if you're not using the current version though, to be
    fair to you, you did say you were using a DataGrid rather than a GridView so
    I should have spotted that...

    Yes, HtmlEncode is new in ASP.NET 2:
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.htmlencode(vs.80).aspx

    However, DataFormatString should work in 1.1 without it:
    http://msdn2.microsoft.com/en-us/li...rols.boundcolumn.dataformatstring(VS.71).aspx
    http://www.thescarms.com/dotNet/formatdata.aspx

    Can you show your markup, please...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Sep 4, 2007
    #5
  6. Final reply I promise!!

    Got it working, the format should look like this ="{0:###,###,##0}"

    Julia

    "Mark Rae [MVP]" wrote:

    > "Julia B" <> wrote in message
    > news:...
    > > Hi all
    > >
    > > I've got a datagrid with column with the numeric format {0:F2}. However
    > > this
    > > format expression does not give the numbers comma separators, which I
    > > need. I
    > > can't use the currency format, because I've got multiple currencies and
    > > currency format automatically picks up your local currency.
    > >
    > > I've searched everywhere for examples and can't find what I need. Has
    > > anyone
    > > got any help they could give me please?

    >
    > <asp:BoundField DataField="MyField" DataFormatString="{0:#0.00}"
    > HtmlEncode="false" />
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
     
    =?Utf-8?B?SnVsaWEgQg==?=, Sep 4, 2007
    #6
    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. rguti

    Number formatting

    rguti, Jun 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    415
    Craig Deelsnyder
    Jun 10, 2004
  2. Luis Esteban Valencia

    Formatting decimal number

    Luis Esteban Valencia, Jan 12, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    545
    Philip Q [MVP]
    Jan 12, 2005
  3. probashi

    Number Formatting Question C#

    probashi, Feb 23, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    16,029
    Karl Seguin
    Feb 23, 2005
  4. thomson

    Number Formatting

    thomson, Aug 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    369
  5. Thor W Hammer

    Formatting a number without rounding

    Thor W Hammer, Nov 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    531
    Karl Seguin
    Nov 22, 2005
Loading...

Share This Page