Culture of the edit form when dealing with dates

10 posts, 0 answers
  1. Dyana
    Dyana avatar
    9 posts
    Member since:
    Aug 2011

    Posted 03 Nov 2011 Link to this post

    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
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 03 Nov 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lobna
    Lobna avatar
    14 posts
    Member since:
    Jan 2013

    Posted 24 Apr 2014 Link to this post

    I have radgrid of GridDateTimeColumn. when I edit it works fine when language is english. When arabic it didn't edit. I tried to change culture of the grid or the column at OnItemCreated but it didn't work too.

    Any help?
  5. Lobna
    Lobna avatar
    14 posts
    Member since:
    Jan 2013

    Posted 24 Apr 2014 in reply to Lobna Link to this post

    fixed. I was changing both the Culture and UICulture properties. now I change UICulture only.
  6. Roger
    Roger avatar
    17 posts
    Member since:
    Aug 2012

    Posted 13 May 2014 in reply to Jayesh Goyani Link to this post

    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
  7. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 15 May 2014 Link to this post

    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.

     
  8. KGBRS
    KGBRS avatar
    2 posts
    Member since:
    Apr 2015

    Posted 03 Apr 2015 in reply to Jayesh Goyani Link to this post

    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.
  9. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 03 Apr 2015 Link to this post

    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.

     
  10. KGBRS
    KGBRS avatar
    2 posts
    Member since:
    Apr 2015

    Posted 04 Apr 2015 in reply to Konstantin Dikov Link to this post

    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


  11. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 08 Apr 2015 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017