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:
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:
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:
The WebDateHelper is as follows:
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.
<
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.