i have a datetime field in a gridview
i need the date field to be null or empty if the database returns either null, “”, or 1/1/0001
how does one achieve this– i seem to be having a brain freeze.
you can see what i have tried below
<asp:TemplateField HeaderText="LastEval" ItemStyle-CssClass="gvColumnSmallCss">
<ItemTemplate >
<asp:Label ID="lblmyLabel" Text='<%# Bind("myField","{0:M/d/yyyy}") %>' runat="server" > </asp:Label>
<%-- Text= ' <%# Eval("myField") !=null ? Convert.ToDateTime(Eval("myField")).ToString("MM/dd/yyyy") : "" %>'
--%>
<%-- Text='<%# Bind("myField","{0:M/d/yyyy}") %>'--%>
</ItemTemplate>
c#
protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string myField;
myField= (e.Row.FindControl("lblmyField") as Label).Text;
DateTime? myField= null;
_myField = string.IsNullOrEmpty(myField)
? (DateTime?)null : (DateTime?)DateTime.Parse(myField);
DateTime checkDate = DateTime.Parse("1/1/00001");
if (lastEval == checkDate.ToString() || myField=="")
{
(e.Row.FindControl("lblmyField") as Label).Text = "";
}
}
}
also tried similar in rowdatabound