473,409 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

How do I Databind Dates or DateTime in ASP.NET 1.x? VB or C# please

Answer is in an article.


Complex DataBinding with Date Formats in .NET 1.1

Did you know that you can do some pretty complex things with .NET's
late binding in ASP.NET 1.X? I had a problem where I needed to be able
to kick out dates in a specific format. I didn't want to use a helper
method, which involves compiled code, so I found a solution.

1<%# CType(DataBinder.Eval(Container.DataItem, "DateAdded"),
DateTime).ToString("dd MMM yyyy") %>

Your datatype on the DataItem can be a string or a DateTime object.
Either way, you must do the conversion first, otherwise there would be
an implicit conversion, which is not allowed in late-binding code. The
bold part is the name of the date property on the object you are
binding against.

As with any late-binding, you'll have a slight performance delay on
the first hit, but that's just cause the page is recompiling. It'll be
fine after that.

posted on Thursday, September 30, 2004 2:31 AM
Feedback
# re: Complex DataBinding with Date Formats in .NET 1.1 9/29/2004
11:48 PM Matt Berther

How about

DataBinder.Eval(Container.DataItem, "DateAdded", "dd MMM yyyy")

Same thing... without the cast.
# re: Complex DataBinding with Date Formats in .NET 1.1 9/30/2004
12:02 AM Robert McLaws

Nope, doesn't work. I get "dd MMM yyyy" as my value. That's why I had
to cast...
# re: Complex DataBinding with Date Formats in .NET 1.1 9/30/2004
12:53 AM LeeB

Or you could use:

CType(Container.DataItem.DateAdded, DateTime).ToString("dd MMM yyyy")
Nov 18 '05 #1
0 1219

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: wireless200 | last post by:
I've got a table with some datetime fields in it. One field (call it field 1) is of the form mm/dd/yyyy and the other two (fields 2 and 3) are in the form of hh:mm:ss:xx where xx is hundreths of...
5
by: Tom | last post by:
It appears that you can't compare two dates in DotNet. You must use ToString and compare the strings. Is that the only reliable way? Try this: Dim dteOne As Date =...
14
by: Frederik Vanderhaeghe | last post by:
Hi, I have made a search page on which users can search for documents. They can search by documentnumber, customername,... and also by date. Now the problem is that when a date is entered it...
3
by: Doug Durrett | last post by:
I'm having an issue and wanted to pass it by everyone to see what you think. Here is my code. //Code Start searchs = new...
2
by: serge | last post by:
/* Subject: How best to use BETWEEN Begin and End Dates to find out if an employee was/is member of any group for a certain date range? You can copy/paste this whole post in SQL Query Analyzer...
5
by: AAJ | last post by:
Hi Does anyone know of any good publically available set of standards for managing dates when dealing with a database server (in my case SQL Server 2000 and c# VS2005). At the moment, if I...
5
by: Smokey Grindle | last post by:
Ok I must admit I stink at regular expressions... been trying to learn them for a while now and its not sticking how I wish it would... but I am trying to take a very long string (about 30KB) and...
2
by: barronmo | last post by:
I'm trying to get the difference in dates using the time module rather than datetime because I need to use strptime() to convert a date and then find out how many weeks and days until that date. ...
1
by: Matt Lowrance | last post by:
I have created an object that has a number of properties, that I am now trying to simply databind to a form. I am using the data designer to do it and just dragging and dropping the items onto the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.