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. Advertising

  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. Advertising

  3. ken s

    ken s Guest

    Thank you for the tip. That did it.
    /Ken
    ken s, Oct 19, 2006
    #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. Brian Candy
    Replies:
    2
    Views:
    1,138
    Janaka
    Feb 18, 2004
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,196
    Michael Borgwardt
    May 30, 2004
  3. Replies:
    5
    Views:
    26,479
    Mike Schilling
    Mar 29, 2006
  4. moonhk
    Replies:
    5
    Views:
    526
    moonhk
    Oct 11, 2006
  5. Ste
    Replies:
    41
    Views:
    783
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
Loading...

Share This Page