This is a migrated thread and some comments may be shown as answers.

Any way to set default display date for a RadDatePicker column as today's date?

2 Answers 791 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dexter
Top achievements
Rank 1
Dexter asked on 30 Apr 2014, 02:23 AM
As per title, when I click to add a new row in my RadGridView, I would like my RadDatePicker column to auto display today's date rather than 1/1/0001.
Is there any way to do this? I've tried to set various properties at design time such as DisplayDate, DateTextTime, SelectedDate but all doesn't make a difference.

I would perhaps try to do it at code-behind rather than design time, but I have no idea how to access it.
Anyways here are my codes currently:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=SvcDate}" UniqueName="SvcDate"
                                            TextWrapping="Wrap" Width="100" TextAlignment="Center" DataFormatString="{}{0:ddMMyy}">
                    <telerik:GridViewDataColumn.Header>
                        <TextBlock Text="Service Date" TextAlignment="Center"/>
                    </telerik:GridViewDataColumn.Header>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <telerik:RadDatePicker SelectedValue="{Binding Path=SvcDate}"
                                                   DateTimeWatermarkContent="Service"
                                                   ErrorTooltipContent="Unrecognised format. Use drop-down interface for input assistance."
                                                   Culture="en-SG" DisplayDateStart="01/01/2014">
                            </telerik:RadDatePicker>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>

2 Answers, 1 is accepted

Sort by
0
Dexter
Top achievements
Rank 1
answered on 01 May 2014, 12:13 PM
Ok I have solved the problem. The binding DataType to the column is DateTime, which don't accept null values. Null values is what the GridView produces upon clicking add new row. When such thing happens, DateTime will auto return 01/01/0001, which is then passed to the RadDatePicker. The solution is to change the datatype to Nullable DateTime, which is 'DataType?'.

This would mean all related codes have to be modified accordingly at back-end to suit the new datatype.
0
Dimitrina
Telerik team
answered on 01 May 2014, 02:41 PM
Hi,

Thank you for sharing your solution with the community. 


Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Dexter
Top achievements
Rank 1
Answers by
Dexter
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or