views:

253

answers:

1

Our interface has the date and time in separate boxes. One box for date (with a DatePicker), one box for time (as a TextBox).

Is it possible to databind a single DateTime (or preferably a nullable DateTime) to these separate values? (If not, what alternatives are there?)

How can this be done?

+1  A: 

In your interface create a public property or method for retrieving the entire date. This method or property will then create the date using your interface fields. What you have done sounds like a user friendly interface as clear separation of the two is logical.

public DateTime GetDateTime(){
    return new DateTime(DateControl.Year,DateControl.Month,DateControl.Day,TimeControl.Hour,TimeControl.Minute);
}

As an example this could be a possible method on your interface which can be consumed!

Subquently you could have a set method which takes a datetime and you then split of the values and bind the two controls. :-)

Andrew

REA_ANDREW
This sounds like a 'no' on the can you bind two controls directly to the date time. The problem is, we would like to bind directly to a dumb message, that does not have anything other than the fields, which in this case is a date time. If not, we'll have to find a work around, but the preference is to do it directly.
Colin Dabritz
As long as your date field HAS a time, then passing that date to a Time Control should just extract the time value and a Date Control the date value. It depends on how the control was built. Is it a .NET user control? Does it have a DataSource property? If it doesn't you could create a wrapper around the control and add the DataBinding yourself.
REA_ANDREW
At this point it is not a control of any kind, it is two separate controls. I see what you mean about the wrapper though. Thanks much for the response.
Colin Dabritz