Here is a nice little trick I found for dealing with data-type DateTime?
I was recently tasked with replacing a different venders UI toolset with yours and had a hard time dealing with nullable dates in existing code.
I finally created an extension method that allows me to quickly grab the text-field's value whether it has been set or not.
I hope this can save someone else time down the road.
I was recently tasked with replacing a different venders UI toolset with yours and had a hard time dealing with nullable dates in existing code.
I finally created an extension method that allows me to quickly grab the text-field's value whether it has been set or not.
I hope this can save someone else time down the road.
public
static
string
outputDate(
this
Telerik.Web.UI.RadDateTimePicker radPicker,
string
formatter)
{
if
(radPicker.IsEmpty || radPicker.SelectedDate ==
null
) {
return
String.Empty; }
switch
(formatter.ToLower())
{
case
"text"
:
case
"date"
:
return
radPicker.SelectedDate.Value.ToShortDateString();
case
"value"
:
case
"datetime"
:
return
radPicker.SelectedDate.Value.ToString();
default
:
try
{
return
radPicker.SelectedDate.Value.ToString(formatter); }
catch
{
return
String.Empty; }
}
}