PDA

View Full Version : Data Binding - Formatting the output


stephenro
07-18-2005, 03:39 PM
I am using the binding capablilities of sping.net and when I bind a NullableDateTime, I only want to display the Date portion of my DateTime attribute. I can't seem to get the format argument of the Binding call correct. Does anyone have an example of how to use the Binding call with the extra format string argument.

TIA

Steve

Aleks Seovic
08-13-2005, 02:12 PM
You should use the same format string you would use with String.Format method and pass it in as an optional parameter:

[Binding("Text", "MyModel.DateProperty", Format = "myFormatString", Direction = BindingDirection.DataModelToControl)]

You probably want to specify optional Direction parameter as well, to tell Spring that it shouldn't try to update data model using formatted value from the control on postback.

HTH,

Aleks

jacksonpd
08-16-2005, 01:09 AM
You could also use the type conversion within the core springframework.

You can then convert between date and text.

Check out the "type conversion" documentation at ...

http://www.springframework.net/doc/reference/html/validation.html#objects-objects-conversion