add a comma

Discussion in 'ASP .Net' started by Ryan Moore, Aug 27, 2003.

  1. Ryan Moore

    Ryan Moore Guest

    how do I format a databound field in a datagrid to place a comma for a
    currency (eg 126,000)

    I'm currently using:

    DataBinder.Eval(Container.DataItem, "price", "{0:c}"

    thanx
     
    Ryan Moore, Aug 27, 2003
    #1
    1. Advertising

  2. You can use the ToString() method, and pass the string "N" to it, as in:

    decimal d = 100000.25
    string s = d.ToString("N"); // returns "100,000.25"

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    http://www.takempis.com
    The more I learn, the less I know.

    "Ryan Moore" <> wrote in message
    news:...
    > how do I format a databound field in a datagrid to place a comma for a
    > currency (eg 126,000)
    >
    > I'm currently using:
    >
    > DataBinder.Eval(Container.DataItem, "price", "{0:c}"
    >
    > thanx
    >
    >
     
    Kevin Spencer, Aug 27, 2003
    #2
    1. Advertising

  3. Ryan Moore

    David Wier Guest

    Try using the DataFormatString Property of your boundcolumn:
    <asp:BoundColumn DataField="Price" DataFormatString="{0:c}" ... />

    David Wier
    http://aspnet101.com
    http://aspexpress.com


    "Ryan Moore" <> wrote in message
    news:...
    > how do I format a databound field in a datagrid to place a comma for a
    > currency (eg 126,000)
    >
    > I'm currently using:
    >
    > DataBinder.Eval(Container.DataItem, "price", "{0:c}"
    >
    > thanx
    >
    >
     
    David Wier, Aug 27, 2003
    #3
  4. "Ryan Moore" <> wrote
    > how do I format a databound field in a datagrid to place a comma for a
    > currency (eg 126,000)
    > I'm currently using:
    > DataBinder.Eval(Container.DataItem, "price", "{0:c}"
    >


    Ryan,
    Try setting the CurrentCulture and CurrentUICulture for the current thread
    in the Application_BeginRequest event handler.

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    ' Initialize the CurrentCulture and CurrentUICulture with the
    ' Browser's user language setting.
    Try
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages(0))
    Catch
    ' Culture not supported. Use US English.
    Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
    End Try
    ' Set the CurrentUICulture to be the same as CurrentCulture
    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
    End Sub

    --

    Thanks,
    Carl Prothman
    Microsoft ASP.NET MVP
    http://www.able-consulting.com
     
    Carl Prothman [MVP], Aug 27, 2003
    #4
  5. This one has always been my favorite for currency in a datagrid.

    DataReader.GetSqlMoney(2).ToDouble().ToString(
    "$#,,##0.00;($#,##0.00);$0.00" );

    has dollar signs, commas and does the () around negative values...

    bill


    DataReader.GetSqlMoney( 2 ).ToDouble().ToString(
    "$#,##0.00;($#,##0.00)" ) );

    "Ryan Moore" <> wrote in message
    news:...
    > how do I format a databound field in a datagrid to place a comma for a
    > currency (eg 126,000)
    >
    > I'm currently using:
    >
    > DataBinder.Eval(Container.DataItem, "price", "{0:c}"
    >
    > thanx
    >
    >
     
    William F. Robertson, Jr., Aug 28, 2003
    #5
    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. Jason Miles
    Replies:
    1
    Views:
    614
    J├╝rgen Exner
    May 28, 2004
  2. Martin Pahlplatz

    server.mappath with comma in foldername?

    Martin Pahlplatz, Nov 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    529
    Martin Pahlplatz
    Nov 11, 2003
  3. Yama

    Comma Delimited

    Yama, Dec 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    407
    Ken Cox [Microsoft MVP]
    Dec 16, 2003
  4. Rasool
    Replies:
    3
    Views:
    536
    mikeb
    Mar 3, 2004
  5. Kevin Spencer

    Re: splitting field by comma

    Kevin Spencer, May 19, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    461
    =?Utf-8?B?UGFvbGE=?=
    May 20, 2004
Loading...

Share This Page