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 its filled it will be parsed into a DateTime and then printed as the default ToString.
For Each row, in 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. Id 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 the problem of empty dates.
Convert.ToDateTime()
On a empty string, will print the default DateTime.
Is there a way that i can fasion an If-Statement in my aspx code, to only perform Convert.ToDateTime if its not an empty string?