Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Can't hide minvalue dates in a GridView

Back to Forum: Tech Off
  • User profile image

    There has to be an easy away around this problem:

    I'm binding a GridView to an object collection (IList) and its displaying data fine.  However, I have one column that is a possible empty date field.  Its null out of my db view and a DateTime.MinValue in my object, but the GridView is rendering it out instead of just leaving it blank.

    Is there an easier way to stop this behavior without resorting to invading the DataBinding event and fixing it manually?


  • User profile image

    You can create a property for a 'FormatedDateTime' and bind to that instead, and make it return the formatted date string. Useful to consolidate how the date is 'formatted' across the platform instead of relying on the ui control to specify it.

  • User profile image

    After some trial and error, here is the solution.  Had to convert the bound column into a template column, then set it up like so:

    <asp:TemplateField HeaderText="Date Processed" SortExpression="DateProcessed">
    <asp:Label ID="Label1" runat="server" Text='<%# ((DateTime)Eval("DateProcessed"))
    == DateTime.MinValue ? "" : Eval("DateProcessed", "{0:d}") %>'>

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.