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

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
 
R

Raterus

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top