如何将Telerik radgridview的默认日期值(1/1/1900)覆盖为xaml中的空值
xaml绑定就像:
<telerik:GridViewDataColumn Header="Estimated Start On" DataMemberBinding="{Binding EstdStartDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,StringFormat=N2}" Width="100" IsFilterable="False" IsGroupable="False">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding EstdStartDate}" Height="30" />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
谢谢, 萨拉蒂
答案 0 :(得分:2)
看看如何实现WPF Value Converters。
查看:
<telerik:GridViewDataColumn DataMemberBinding="{Binding DateColumn, Converter={StaticResource MyDateConverter}" IsReadOnly="True">
转换器:
public class MyDateConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DateTime)
{
DateTime test = (DateTime) value;
if (test.Year > 1900) // If year is greater than 1900 then display
{
string date = test.ToString("d/M/yyyy"); // Your date format
return date;
}
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
答案 1 :(得分:0)
尝试转换默认值。这里的DateTime.MinValue是默认值
if (EndDate == DateTime.MinValue)
{
Response.Write("Null");
}