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

Culture of the edit form when dealing with dates

8 Answers 254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dyana
Top achievements
Rank 1
Dyana asked on 03 Nov 2011, 01:26 PM
Hello,

I'm looking for a way to control the culture of the edit form that is created by a radgrid's edit button

I've got a radgrid connected to a simple objectdatasource.
There are two date values in the object.
This is my page load:

        protected void Page_Load(object sender, EventArgs e)
        {
            RadGrid1.Culture = new CultureInfo("en-GB");
            //RadGrid1.Rebind();
        }

I've set DataFormatString="{0:dd/MM/yyyy}" on the date gridboundcolumns

Now the problem is, the dates are in en-GB in the grid, but when clicking edit, the format is assumed to be en-US

basically I can have a date of 2/11/2011 (November 2, 2011) in the grid, click edit and see 2/11/2011 in the edit box, click update, and the radgrid now displays 11/2/2011 (February 11, 2011), if I click edit again and update, the radgrid will display 2/11/2011

Now, this time when I click edit, if I enter 2 November 2011, then the date is passed correctly, in en-GB. This makes me think that this edit form is assuming en-US, even though the grid (and the thread culture) is en-GB.

Adding the RadGrid1.Rebind(); to the page load seems to fix the problem,  but then multple edit buttons start appearing

8 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Nov 2011, 01:43 PM
Hello,

you can also set culture to datepicker On insert/Edit mode.
<telerik:GridDateTimeColumn DataField="myData" UniqueName="myData" HeaderText="myData" PickerType="DatePicker"></telerik:GridDateTimeColumn>
void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            RadDatePicker dp = item["myData"].Controls[0] as RadDatePicker;
           dp.Culture = "Set your culture here";
        }
}


Thanks,
Jayesh Goyani
0
Lobna
Top achievements
Rank 1
answered on 24 Apr 2014, 09:59 AM
fixed. I was changing both the Culture and UICulture properties. now I change UICulture only.
0
Roger
Top achievements
Rank 1
Veteran
answered on 13 May 2014, 07:11 AM
It's a pitty that Culture property is missing in GridDateTimeColumn. I came across same issue and expected to find the property in this control as it is available in RadDatePicker. It would be much more convenient.

Cheers,
Roger
0
Konstantin Dikov
Telerik team
answered on 15 May 2014, 06:57 AM
Hello Roger,

Since the columns are part of the grid, in order to change the Culture you will have to set it directly to the grid, not to a particular column. Since changing the culture to one column only is not expected to be a common practice, that is the reason why there is no exposed property for the date/time pickers's culture in the column. 

Nevertheless, you could always use the approach suggested by Jayesh, where you set the Culture property directly to the date/time picker control or use a GridTemplateColumn instead.


Kind Regards,
Konstantin Dikov
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.

 
0
KGBRS
Top achievements
Rank 1
answered on 03 Apr 2015, 02:05 PM
Hi ,
<telerik:GridDateTimeColumn UniqueName="std" DataField="StartDate" HeaderText="Nothing"></telerik:GridDateTimeColumn>I want to bind the date in ar-SA culture(aurab) when im when im adding the GridDateTimeColumn it is getting error page. thanks in advance.
0
Konstantin Dikov
Telerik team
answered on 03 Apr 2015, 03:46 PM
Hi Siva,

Please share the error that you are receiving and provide some additional information about the data type of your "StartDate" field.

Looking forward to your reply.


Regards,
Konstantin Dikov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
KGBRS
Top achievements
Rank 1
answered on 04 Apr 2015, 05:02 AM

Hi Konstantin
Dikov,

<telerik:RadGrid runat="server" AllowFilteringByColumn="true" ID="RadGrid1"

        AutoGenerateColumns="false"  OnNeedDataSource="RadGrid1_NeedDataSource"

         OnItemDataBound="RadGrid1_ItemDataBound">

        <MasterTableView>

            <Columns>

               
<telerik:GridBoundColumn DataField="OrgFeeScheduleID"
HeaderText="ID">

               
</telerik:GridBoundColumn>

               
<telerik:GridBoundColumn DataField="Name"
HeaderText="Item">

               
</telerik:GridBoundColumn>                                        

               
<telerik:GridDateTimeColumn
UniqueName="std"
DataField="StartDate"
HeaderText="StartDate"></telerik:GridDateTimeColumn>                                

            </Columns>

        </MasterTableView>

    </telerik:RadGrid>

This is my grid I want to display the data based on the
culture (ar-SA) when im  running the page
It is getting error page because of GridDateTimeColumn

Error Message:

Valid values are between
1318 and 1500, inclusive.

Parameter name: year

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code. 



Exception Details: System.ArgumentOutOfRangeException: Valid values are between 1318
and 1500, inclusive.

Parameter name: year

I try to apply DateTimeFormat as GregorianCalendar but i field

Thanks&Regard's

Siva


0
Konstantin Dikov
Telerik team
answered on 08 Apr 2015, 10:43 AM
Hi Siva,

In order to change the calendar to Gregorian calendar correctly in this particular scenario, you will have to override the InitializeCulture method on the page as shown below:
protected override void InitializeCulture()
{
    culture = new System.Globalization.CultureInfo("ar-SA");
    culture.DateTimeFormat.Calendar = new GregorianCalendar();
 
    Thread.CurrentThread.CurrentCulture = culture;
    Thread.CurrentThread.CurrentUICulture = culture;
 
    base.InitializeCulture();
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Dyana
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Lobna
Top achievements
Rank 1
Roger
Top achievements
Rank 1
Veteran
Konstantin Dikov
Telerik team
KGBRS
Top achievements
Rank 1
Share this question
or