Date format hiding null values

Discussion in 'ASP .Net Datagrid Control' started by ken s, Oct 18, 2006.

  1. ken s

    ken s Guest

    Greetings,
    I'm using a custom date format to display date values in a BoundField in a
    GridView. Here's the line that formats the date value:

    DataFormatString="{0:MM/dd/yy}"

    It works fine as long as there's a date in the field being displayed. But
    if the field is null, it displays 01/01/01. I'd prefer that it either show a
    blank field when it's null. How can I do this?
     
    ken s, Oct 18, 2006
    #1
    1. Advertisements

  2. Handle RowDataBound (or ItemDataBound) event. For ever row item check the
    value in the data field (available via DataItem property). If it is null,
    set the required cell (available via Cells property) text to blank.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "ken s" <> wrote in message
    news:...
    > Greetings,
    > I'm using a custom date format to display date values in a BoundField in a
    > GridView. Here's the line that formats the date value:
    >
    > DataFormatString="{0:MM/dd/yy}"
    >
    > It works fine as long as there's a date in the field being displayed. But
    > if the field is null, it displays 01/01/01. I'd prefer that it either
    > show a
    > blank field when it's null. How can I do this?
    >
     
    Eliyahu Goldin, Oct 18, 2006
    #2
    1. Advertisements

  3. ken s

    ken s Guest

    Thank you for the tip. That did it.
    /Ken
     
    ken s, Oct 19, 2006
    #3
    1. Advertisements

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. Brian Candy
    Replies:
    2
    Views:
    1,429
    Janaka
    Feb 18, 2004
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,775
    Michael Borgwardt
    May 30, 2004
  3. Replies:
    5
    Views:
    30,228
    Mike Schilling
    Mar 29, 2006
  4. Chu
    Replies:
    3
    Views:
    4,476
    Shawn
    Aug 15, 2006
  5. moonhk
    Replies:
    5
    Views:
    779
    moonhk
    Oct 11, 2006
  6. Douglas J. Badin

    &nbsp; is not generated for null values when using a format string

    Douglas J. Badin, Dec 2, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    283
    Jeffrey Tan[MSFT]
    Dec 4, 2003
  7. Josh Sharpe
    Replies:
    1
    Views:
    328
    Brian Candler
    Sep 21, 2010
  8. Ste
    Replies:
    41
    Views:
    1,217
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
Loading...