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

[Solved] Datetime required field and minimum value

1 Answer 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sheryl Stoller
Top achievements
Rank 1
Sheryl Stoller asked on 15 Feb 2012, 10:19 PM
Hello! 

I have a database value that is a datetime, not null - when i use editing in my radgrid, it pops up with a default value for that datetime. That default value is 1/1/2001 12:00 AM. I would like this to default to the current date time instead. I need this to be a required field, so changing the database to allow nulls is not an option.

How can i change this?

Thanks!
-S

1 Answer, 1 is accepted

Sort by
0
Sheryl Stoller
Top achievements
Rank 1
answered on 16 Feb 2012, 03:57 PM
I figured this out on my own, but here's the answer for anyone else that needs it:

<%if (Model.HasValue && Model.Value == default(DateTime))
  { %>
<%= Html.Telerik().DateTimePickerFor(m => m).Value(DateTime.Now) %>
<%}
  else
       
  {
%>
<%= Html.Telerik().DateTimePickerFor(m => m) %>
<%} %>

This makes it so that if it's a new record, the datetime defaults to today. if it's not, it keeps the values in the record.

Thanks!
-S
Tags
Grid
Asked by
Sheryl Stoller
Top achievements
Rank 1
Answers by
Sheryl Stoller
Top achievements
Rank 1
Share this question
or