Re: Date format in repeater control
- From: "Teemu Keiski" <joteke@xxxxxxxxxxxxxxx>
- Date: Tue, 12 Jul 2005 18:01:01 +0300
Hi,
if you don't need to cast to a date first, you could simply have a
databinding expression in the aspx. For example:
<asp:TemplateColumn>
<ItemTemplate>
<%#
DataBinder.Eval(Container.DataItem,"database_field_name","{0:dd.MM.yyyy}")%>
</ItemTemplate>
</asp:TemplateColumn>
where "{0:dd.MM.yyyy}" indicates the formatting. Now, databinding
expressions should not blow up with null values (DBNull), they just produce
empty string.
However, if you need to cast to a date in code, you can nothing but check
for the DbNull value from the field with IsDbNull function (VB) or
Convert.IsDbNull (Framework/C#) which return boolean value indicating if the
value is DbNull. When there is a DbNull (per previous methods) you just
outout empty string (or other predefined string such as -No date-), you
cannot cast it to a Date. So it means that this check should happen before
trying casting.
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
.
- Follow-Ups:
- Re: Date format in repeater control
- From: zdrakec
- Re: Date format in repeater control
- References:
- Date format in repeater control
- From: zdrakec
- Date format in repeater control
- Prev by Date: Re: control question - calendar
- Next by Date: HttpWorkerRequest.ReadEntityBody returns 0
- Previous by thread: Re: Date format in repeater control
- Next by thread: Re: Date format in repeater control
- Index(es):
Relevant Pages
|