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

[Solved] MVC Grid DatetimePicker format

4 Answers 233 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.
chris
Top achievements
Rank 1
chris asked on 27 Feb 2011, 09:08 AM
When I deployed this to the server I get the error of "The value '18/05/1974' is not valid for D.O.B.." when doing in grid editing

My View:
<%= Html.Telerik().Grid<SDAC.Models.Runner>()
        .Name("Grid")
        .DataKeys(keys =>
        {
            keys.Add(p => p.id);
        })
        .ToolBar(commands => commands.Insert().ButtonType(type).ImageHtmlAttributes(new
            {style="margin-left:0"}))
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
                .Select("_Select", "Runner")
                .Insert("_Insert", "Runner")
                .Update("_Save", "Runner")
                .Delete("_Delete", "Runner");
        })
        .Columns(columns =>
        {
            columns.Bound(o => o.lastname);
            columns.Bound(o => o.firstname);
            columns.Bound(o => o.sex).Width(40);
            columns.Bound(o => o.Active).Width(40);
            columns.Bound(o => o.dob).Format("{0:dd/MM/yyyy}").Width(100);
  
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(type);
                commands.Delete().ButtonType(type);
            }).Width(180).Title("Commands");
        })
            .Editable(editing => editing.Mode(mode))
            .Scrollable(scrolling => scrolling.Enabled(false))
            .Sortable(sorting => sorting.Enabled(true))
            .Pageable(paging => paging.PageSize(10))
            .Filterable(filtering => filtering.Enabled(true))
            .Groupable(grouping => grouping.Enabled(true))
            .Footer(true)
%>

Editor Template Date.ascx
<%= Html.Telerik().DatePicker()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty) + DateTime.Now.Millisecond.ToString() })
        .Value(Model > DateTime.MinValue? Model : DateTime.Today)
        .Format("dd/MM/yyyy")
%>

See attached screenshot.
If I input the date in my desired format (dd/MM/yyyy) I get the format validation error.
If I input the date in US format (MM/dd/yyyy) the value is saved and then displayed in the correct dd/MM/yyyy format.
What do I need todo so that I do not get this validation error?

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 28 Feb 2011, 08:08 AM
Hello chris,

 You need to set the current culture to en-UK and enable globalization for the script registrar:

<%= Html.Telerik().ScriptRegistrar().Globalization(true) %>

Regards,
Atanas Korchev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
chris
Top achievements
Rank 1
answered on 28 Feb 2011, 08:51 AM
Thanks for your help.
Where / how should I set the culture?
0
Atanas Korchev
Telerik team
answered on 28 Feb 2011, 09:16 AM
Hi chris,

 You can check the How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization MSDN help article.

Greetings,
Atanas Korchev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
chris
Top achievements
Rank 1
answered on 28 Feb 2011, 07:33 PM
Thank you. This worked perfectly.

I added the following line under system.web in my web.config

<globalization uiCulture="en" culture="en-GB" />
and changed my script registrar

<%= Html.Telerik().ScriptRegistrar().Globalization(true) %>
Tags
Grid
Asked by
chris
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
chris
Top achievements
Rank 1
Share this question
or