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

Let the user select NULL as the Date

3 Answers 68 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Joseph
Top achievements
Rank 1
Joseph asked on 26 May 2011, 05:28 AM
Hi All,

Ok so the full scenario is i have a grid and in that grid is a column bound to a Nullable Date. Let's call this column "End Date".
Clearly not all things have an end date so end date can be null.

I want to use an editor template to turn the start date text field into a datepicker when in edit mode. Problem is...

How can the user select the null date? Is it possible?


regards,
James

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 26 May 2011, 10:21 AM
Hello Joseph,

You can achieve your goal using edit template for the aforementioned Nullable<DateTime> property. The edit template should be strongly-typed and the defined model should be Nullable<DateTime>. Thus you can show DatePicker UI component which accepts Nullable<DateTime>. You can check EditTemplates provided with Telerik Extensions for ASP.NET MVC. In order end user to enter null for End Date should just clear input field and update the edited row.

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kevin
Top achievements
Rank 1
answered on 06 Oct 2011, 07:44 PM
Georgi, 
The standard telerik DatePicker editor template already has a nullable DateTime model:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>
 
<%= Html.Telerik().DatePickerFor(m => m) %>

I even tried to change it to Nullable<DateTime> and it has the same results.  Can you provide some more detail here?  Is there an example of this working in a grid on your online demos?

Steve
0
Kevin
Top achievements
Rank 1
answered on 06 Oct 2011, 09:54 PM
I fixed this using the razor editor template:
@model Nullable<DateTime>
 
@(Html.Telerik().DatePicker()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper" })
        .Value(Model)
)

This editor template was used in this demo: http://demos.telerik.com/aspnet-mvc/razor/datepicker/edittemplate
The interesting thing is the online demo is broken.  When you clear out the date field it takes you to a page saying "Sorry, we couldn't find the page you're looking for."

Steve
Tags
Date/Time Pickers
Asked by
Joseph
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or