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”;}
else
{return discontinued.ToString();}
}
Template field in DetailsView looks like.
<ItemTemplate>
<asp:Label ID=”Label6″ runat=”server” Text=’<%# ReplaceDefaultDateAsNA((DateTime) Eval(“LastPasswordChangedDate”)) %>’></asp:Label>
</ItemTemplate>
Reference (very good article): http://static.asp.net/asp.net/files/DataTutorials/datatutorial13cs.pdf