User-893317190 posted
Hi JagjitSingh,
You could deal with simple logic in <%# %>.
Below is my code.
if (!IsPostBack)
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("date", typeof(DateTime)));
table.Columns.Add(new DataColumn("id", typeof(int)));
table.Rows.Add(DBNull.Value,1);
table.Rows.Add(DBNull.Value,2);
table.Rows.Add(new DateTime(1721, 02, 05),3);
table.Rows.Add(new DateTime(1753, 01, 01),4);
table.Rows.Add(new DateTime(1567, 09, 02),5);
GridView1.DataSource = table;
GridView1.DataBind();
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="id" HeaderText="id" />
<asp:TemplateField HeaderText="date">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("date") as DateTime? ==new DateTime(1753, 01, 01)?"":Eval("date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The result.

But this way only applies to simple logic, if your logic is complex, it should be written in RowDataBound.
Or you could write your sql to deal with your problem using case. Case is like if else in c#.
As to null, gridview will change null to string.empty automatically.
select
case
when date1 ='1999-02-12'
then null
else date1
end
from period
Best regards,
Ackerly Xu