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

setting RadDateTimePicker selecteddate with null or empty

2 Answers 281 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Benjamin asked on 18 Nov 2016, 10:16 AM

 I have added my RadDateTimePicker to a asp:Repeater. on first load the data binding will be empty and this cause the error Value of '1/1/0001 12:00:00 AM' is not valid for 'SelectedDate'. 'SelectedDate' should be between 'MinDate' and 'MaxDate'

i would like to know how to i set the selecteddate to empty string or null value.

i have tried to set the selecteddate to current datetime, but it screw up the timepicker format and the interval setting


i tried doing  DateTime.Now.ToString("dd/MM/yyy HH:mm") and got the error

System.FormatException: String was not recognized as a valid DateTime


my markup

01.<asp:Repeater ID="rptReplyDate" runat="server" OnItemDataBound="rptReplyDate_ItemDataBound">
02.    <HeaderTemplate>
03.        <table cellpadding="0px" cellspacing="0px" class="mainTable">
04.    </HeaderTemplate>
05.    <FooterTemplate>
06.        </table>
07.    </FooterTemplate>
08.    <ItemTemplate>
09.        <tr>
10.            <td style="padding: 1em 1em;">
11.                <table cellpadding="0px" cellspacing="0px" class="repeaterTable">
12.                    <tr>
13.                        <td>
14.                            <telerik:RadDateTimePicker ID="txtReplayDate" runat="server" SelectedDate='<%# Convert.ToDateTime( DataBinder.Eval(Container.DataItem, "completetion")) %>'>
15.                                <TimeView TimeFormat="HH:mm:ss" runat="server">
16.                                </TimeView>
17.                                <DateInput DisplayDateFormat="dd/MM/yyyy HH:mm" runat="server">
18.                                </DateInput>
19.                            </telerik:RadDateTimePicker>
20.                        </td>
21.                    </tr>
23.                </table>
24.            </td>
25.        </tr>
26.    </ItemTemplate>

my code

01.protected void Page_Load(object sender, EventArgs e)
02.        {
03.            if (!Page.IsPostBack)
04.            {
05.                List<ReplayDate> col = new List<ReplayDate>();
06.                ReplayDate newData = new ReplayDate();
07.                newData.completetion = DateTime.Now.ToString();
08.       = 0;
09.                col.Add(newData);
10.                rptReplyDate.DataSource = col;
11.                rptReplyDate.DataBind();
13.             }
15.    public class ReplayDate
16.    {
17.        public int id { get; set; }
18.        public string completetion { get; set; }
19.    }

2 Answers, 1 is accepted

Sort by
Telerik team
answered on 21 Nov 2016, 09:39 AM
Hello Benjamin,

Your example is running correct on my machine. However since you bind the date objects as string it may actually fail if the culture is different.

I would suggest you to bind directly to the DateTime object, and to avoid cast it to string.

<telerik:RadDateTimePicker ID="txtReplayDate" runat="server"
    SelectedDate='<%# DataBinder.Eval(Container.DataItem, "completetion") %>'>
    <TimeView TimeFormat="HH:mm:ss" runat="server">
    <DateInput DisplayDateFormat="dd/MM/yyyy HH:mm" runat="server">

protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
        List<ReplayDate> col = new List<ReplayDate>();
        ReplayDate newData = new ReplayDate();
        newData.completetion = DateTime.Now; = 0;
        rptReplyDate.DataSource = col;
public class ReplayDate
    public int id { get; set; }
    public DateTime? completetion { get; set; }

This way the binding will work culture independent, and you will able to localize it further.

Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
Top achievements
Rank 1
answered on 22 Nov 2016, 01:54 AM
Thanks Vasil, that solve my problem
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Top achievements
Rank 1
Share this question