Datagrid, empty date: How show nothing for date value - now shows 1/1/0001??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have a column in my datagrid that can have values of null at times. I am not assigning any value to it, if it is coming from Database empty. Now, the problem is I guess the datetime variables have a default value. Thus shows an undesirable value of 1/1/0001

How do I go about not showing anything when the value is null like this

Thanks in advance
Reza
 
are you sure they are nulls or just empty data fields. (In my experience
"nulls" crash things if you haven't specifically coded around them) Either
way, you should be able to define a function that you can put in your
databinding syntax <%# %> or in your itemdatabound event that will give you
the date you want. Your function would be something like this.

Private Function getDate(ByVal myDate As Object) As String
getDate = CStr(myDate)

If getDate = "1/1/0001" Then
getDate = String.Empty
End If

Return getDate
End Function

then in your datagrid, define a templatecolumn for this column
<asp:templatecolumn headertext="Date">
<itemtemplate>
<%# getDate(DataBinder.Eval(Container.DataItem, "myDate")) %>
</itemtemplate>
</asp:templatecolumn>

hope this helps
--Michael

Reza said:
Hi,

I have a column in my datagrid that can have values of null at times. I am
not assigning any value to it, if it is coming from Database empty. Now, the
problem is I guess the datetime variables have a default value. Thus shows
an undesirable value of 1/1/0001.
 
Back
Top