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

Unable to set TimePicker to 24 hour values when used in a GridDateTimeColumn

1 Answer 117 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 15 Oct 2014, 05:55 PM
In my application, I have a telerik:RadGrid that contains columns of different types.  One of the columns is a telerik:GridDateTimeColumn and is dfined as follows:

<telerik:GridDateTimeColumn PickerType="TimePicker" UniqueName="BreakStartDateTime"
       HeaderText="<% $Resources:PageControls, StartTime %>" DataField="BreakStartDateTime"
       DataFormatString="{0:t}">
       <HeaderStyle Wrap="false" Width="50px" />
 </telerik:GridDateTimeColumn>


In my code behind, I do a PreRender on this table so that I can set the DataFormatString according to a system option on how the client would like this data to be displayed in the Grid.  That code is as follows:

protected void grdBreaksList_PreRender(object sender, System.EventArgs e)
{
    if (Session[SESSION_BREAK_DATA] != null)
    {
        foreach (GridColumn column in grdBreaksList.Columns)
        {
            if (column.UniqueName == "BreakStartDateTime" || column.UniqueName == "BreakEndDateTime")
            {
                if (SysOption.IsDisplayTime24HourClock)
                {
                    (column as GridBoundColumn).DataFormatString = "{0:HH:mm}";
                }
                else
                {
                    (column as GridBoundColumn).DataFormatString = "{0:t}";
                }
            }
        }
        grdBreaksList.Rebind();
    }
}

All of this works great and the data in the Grid displays as it should based on how the system option is configured to display the time.

The issue is when we try to edit or insert a new row for this grid, we are not able to set the format for the values in the TimePicker.  We can set the format for the field when the value is picked, but we are unable to set the format for the values in the TimePicker popup that shows times to choose.  We set the format of the editable/insertable field as follows in the ItemDataBound for the grid:

if (((e.Item is GridDataInsertItem) || (e.Item is GridEditableItem)) && e.Item.IsInEditMode)
{
    GridEditableItem dataItem = (GridEditableItem)e.Item;
    RadTimePicker picker = (RadTimePicker)dataItem["BreakStartDateTime"].Controls[0];
    WebDateHelper.SetTwentyFourHourAttributes(picker);
 
}

The WebDateHelper is as follows:

    public static void SetTwentyFourHourAttributes(RadTimePicker inControl)
    {
        StringBuilder format = new StringBuilder();
        CultureInfo culture;
 
        if (SysOption.IsDisplayTime24HourClock)
        {
            format.Append("HH:mm");
        }
        else
        {
            format.Append("hh:mm tt");
        }
 
        if (PremisePrincipal.Current != null && PremisePrincipal.Current.LocalityCd != null)
        {
            culture = new CultureInfo(PremisePrincipal.Current.LocalityCd);
        }
        else
        {
            culture = new CultureInfo(SysOption.DefaultLocalityCd);
        }
 
        inControl.DateInput.Culture = culture;
        inControl.TimeView.TimeFormat = format.ToString();
        inControl.DateInput.DateFormat = format.ToString();
        inControl.DateInput.DisplayDateFormat = format.ToString();
    }
}


Doing this formats the field correctly, but the pickable values are ALWAYS in the "hh:mm tt" format.

Any thoughts or suggestions would be greatly appreciated.



1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 20 Oct 2014, 11:46 AM
Hi Eric,

I already answered to the support ticket you have opened for this issue, however I will post my answer here also, so that it could help other users that are facing similar issue:

"Note that the TimePicker controls into the RadGrid are using Shared TimeView for performance optimization.

Therefore in your case you should set the TimeFormat for the Shared TimeView of the picker control like this:

Copy Code
public static void SetTwentyFourHourAttributes(RadTimePicker inControl)
{
StringBuilder format = new StringBuilder();
CultureInfo culture;
if (SysOption.IsDisplayTime24HourClock)
{
format.Append("HH:mm");
}
else
{
format.Append("hh:mm tt");
}
if (PremisePrincipal.Current != null && PremisePrincipal.Current.LocalityCd != null)
{
culture = new CultureInfo(PremisePrincipal.Current.LocalityCd);
}
else
{
culture = new CultureInfo(SysOption.DefaultLocalityCd);
}
inControl.DateInput.Culture = culture;
inControl.SharedTimeView.TimeFormat = format.ToString();
inControl.TimeView.TimeFormat = format.ToString();
inControl.DateInput.DateFormat = format.ToString();
inControl.DateInput.DisplayDateFormat = format.ToString();
}
}

I hope this helps.
"


Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Eric
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or