Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Datagrid, empty date: How show nothing for date value - now shows 1/1/0001?? (http://www.velocityreviews.com/forums/t74166-datagrid-empty-date-how-show-nothing-for-date-value-now-shows-1-1-0001-a.html)

=?Utf-8?B?UmV6YQ==?= 02-27-2004 02:06 PM

Datagrid, empty date: How show nothing for date value - now shows 1/1/0001??
 
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

Raterus 02-27-2004 08:46 PM

Re: Datagrid, empty date: How show nothing for date value - now shows 1/1/0001??
 
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" <uwhockey@hotmail.com> wrote in message
news:F642EB8F-FAE2-4F26-9CB1-B3CF6BA5E9DF@microsoft.com...
> 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





All times are GMT. The time now is 05:38 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.