Data Handling in ASP.Net DetailsView

Filed in .Net Leave a comment

I have a date field in my DetailsView and the date which is coming from DB is the default date which is “1/1/1754 5:00:00 AM”. I need to set the value of this template field to “N/A” if it is default date.

I created below method in my code behind.

protected string ReplaceDefaultDateAsNA(DateTime discontinued)


if (discontinued.ToString() == “1/1/1754 5:00:00 AM”)

{return “N/A”;}


{return discontinued.ToString();}


Template field in DetailsView looks like.


<asp:Label ID=”Label6″ runat=”server”¬†Text=’<%# ReplaceDefaultDateAsNA((DateTime) Eval(“LastPasswordChangedDate”)) %>’></asp:Label>


Reference (very good article):