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

Formatting a date for different regions

2 Answers 477 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Polaris431
Top achievements
Rank 1
Polaris431 asked on 06 Aug 2009, 06:25 AM

When the grid runs in a german version of IE on a german version of the operating system, date columns show their dates using periods separating the day, month and year. What I really want is the format to be whatever I set it to be on the server using whatever regional setting applies to the user. The regional setting is independent of the browser's language or the language of the operating system. It is a web application setting specific for the user. Here is my code example:

DateTimeFormatInfo dateTimeFormat = new CultureInfo("en-us", false).DateTimeFormat;  
GridDateTimeColumn colSessionStartTime = this.RadGridSkillsData.Columns.FindByUniqueName("SessionStartTimeLocal") as GridDateTimeColumn;  
colSessionStartTime.DataFormatString = "{0:" + dateTimeFormat.ShortDatePattern + " " + dateTimeFormat.LongTimePattern + "}"; 

When I view what colSessionStartTime.DataFormatString is set to, it shows up as:

"{0:M/d/yyyy h:mm:ss tt}"

Yet the values that appear in the grid are showing periods rather than slashes for the date.

How can I get the date to format according to any culture code?

Johann

2 Answers, 1 is accepted

Sort by
0
Polaris431
Top achievements
Rank 1
answered on 06 Aug 2009, 06:40 AM
The solution I found was as follows. In the NeedDataSource event, set the current thread's locale as follows: 

 

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); // Or whatever locale you need.  
 

The RadGrid will automatically format the date/time to this locale. I personally find this a lacking feature in the RadGrid. The RadGrid should have a CultureCode property that developers can set. The RadGrid would set its own current thread to the culture code and shouldn't affect the culture of the application. After all, if the DataFormatString allows you to specify the type of delimiter and the RadGrid is not using it, that should be considered a bug.

 

Note: In the event that the culture code for the grid is different than for what is required for the current thread or put another way, if changing the culture code results in no data showing up in the grid, you should change the current thread's culture code only immediately before  the grid's datasource is set:

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("de-de");  // German-Germany
this.RadGridSkillsData.DataSource = tableGoalSessions
0
Daniel
Telerik team
answered on 11 Aug 2009, 04:20 PM
Hello Johann,

Thank you for sharing your code with our community. Our development team will examine the suggestions you offer.

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Polaris431
Top achievements
Rank 1
Answers by
Polaris431
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or