Hey haider6.9,
Please refer below sample.
HTML
<asp:GridView runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="Birth" HeaderText="Birth" DataFormatString="{0:dd/MM/yyyy}" SortExpression="Birth" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Test]"></asp:SqlDataSource>
Code
C#
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime birthDate = Convert.ToDateTime(e.Row.Cells[1].Text);
if (birthDate.ToShortDateString() == "1/1/1900")
{
e.Row.Cells[1].Text = "null";
}
}
}
VB.Net
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim birthDate As DateTime = Convert.ToDateTime(e.Row.Cells(1).Text)
If birthDate.ToShortDateString() = "1/1/1900" Then
e.Row.Cells(1).Text = "null"
End If
End If
End Sub
Screenshot
