Gridview column formatting

Discussion in 'ASP .Net Datagrid Control' started by et, Jan 15, 2007.

  1. et

    et Guest

    I have tried everything to display a bound column in a gridview to 2
    decimals only. The column is a price, and when I run the query in sql, he
    value displays as 10.00. Yet in the grid view it displays as 10.0000. I
    have tried various settings in the dataformatstring, and it seems to ignore
    everything I put there; I've tried: {0}, {0:F2}, {0:d}, {0:c}, among
    others. What am I doing wrong?
    et, Jan 15, 2007
    #1
    1. Advertising

  2. hook into the itemdatabound event handler and set the cell the way you want
    it. consider
    e.item.cells[colInQuestion].Text = "#.##";//picture format

    --
    Regards,
    Alvin Bruney
    ------------------------------------------------------
    Shameless author plug
    Excel Services for .NET is coming...
    OWC Black book on Amazon and
    www.lulu.com/owc

    "et" <> wrote in message
    news:...
    >I have tried everything to display a bound column in a gridview to 2
    >decimals only. The column is a price, and when I run the query in sql, he
    >value displays as 10.00. Yet in the grid view it displays as 10.0000. I
    >have tried various settings in the dataformatstring, and it seems to ignore
    >everything I put there; I've tried: {0}, {0:F2}, {0:d}, {0:c}, among
    >others. What am I doing wrong?
    >
    Alvin Bruney [MVP], Jan 17, 2007
    #2
    1. Advertising

  3. Set HtmlEncode = false for the column.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "et" <> wrote in message
    news:...
    >I have tried everything to display a bound column in a gridview to 2
    >decimals only. The column is a price, and when I run the query in sql, he
    >value displays as 10.00. Yet in the grid view it displays as 10.0000. I
    >have tried various settings in the dataformatstring, and it seems to ignore
    >everything I put there; I've tried: {0}, {0:F2}, {0:d}, {0:c}, among
    >others. What am I doing wrong?
    >
    Eliyahu Goldin, Jan 18, 2007
    #3
    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. Keithb
    Replies:
    2
    Views:
    1,132
  2. Replies:
    2
    Views:
    536
  3. Just Me
    Replies:
    1
    Views:
    393
    Mark Rae [MVP]
    Oct 30, 2007
  4. Keith G Hicks
    Replies:
    3
    Views:
    763
    Keith G Hicks
    Feb 18, 2008
  5. Bobby Edward

    Formatting gridview column: mm/dd/yy

    Bobby Edward, Nov 13, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    726
    Bobby Edward
    Nov 15, 2008
Loading...

Share This Page