Set default value of RadDatePicker to NULL when date is not set

安稳与你 提交于 2019-12-31 07:31:32

问题


I'm binding the RadDatePicker to a viewModel dateTime property. when the property is null in database i get 01/01/0001. How to i change this behavior to just leave the date field blank.. example:

In database ===> experiation_date : NULL In View(GUI) ===> experation_date : 01/01/0001

Expected Result ===> experation_date : {Blank}


回答1:


Set the SelectedDate to null (and not DBNull):

RadDatePicker1.SelectedDate = null;

and in xaml set DateTimeWatermarkContent to the empty string:

<telerik:RadDatePicker x:Name="RadDatePicker1" DateTimeWatermarkContent="" />



回答2:


If you are bind not nullable datetime variable i.e (DateTime) to control then it will use default 01/01/001 date instead of Empty.... So if you want the default value as a Empty then just change the datatype of your variable which is bound to control to (DateTime?).....

DateTime ===> DateTime?

It works fine...

Thank you.!!!



来源:https://stackoverflow.com/questions/10207038/set-default-value-of-raddatepicker-to-null-when-date-is-not-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!