I have a DateTime object that I need to print in a custom gridlike control.
The type of the data I want to print is a date in the format dd-mm-yyyy.
This value can be either filled or blank.
If it's filled it will be parsed into a DateTime and then printed as the default ToString.
For each row, I can use
<CellTemplate>
<asp:Literal ID="Literal2" runat="server" Text="<%# Container.Value %>"></asp:Literal>
</CellTemplate>
But this prints the default long version of the date. I'd like the format from ToShortDateString().
So I tried modifying to:
<CellTemplate>
<asp:Literal ID="Literal2" runat="server" Text="<%# Convert.ToDateTime(Container.Value).ToShortTimeString()%>"></asp:Literal>
</CellTemplate>
This works as intended.
Now I have a problem with empty dates,
Convert.ToDateTime()
On an empty string, it will print the default DateTime.
Is there a way that I can fashion an If-Statement in my aspx code, to only perform Convert.ToDateTime, if it's not an empty string?