How to change format of DatePicker in GridView

3 posts, 1 answers
  1. Stephen
    Stephen avatar
    43 posts
    Member since:
    Apr 2012

    Posted 08 Oct 2012 Link to this post

    I have been trying to figure out how to hide the time portion of the RadDatePicker, when I am using it inside of a Grid.  I have been looking at the picker help here: http://www.telerik.com/help/silverlight/raddatetimepicker-features-formatting.html but this doesn't work when it is in a GridView, or at least it isn't working for me.

    I am using the control inside of a DataColumn, because I need to use the DisplayDateStart and DisplayDateEnd properties, so I cannot just use the basic DataColumn, without the picker control in it.

    Here is my example code.  Everything works great when you are editing the row in the grid, it doesn't show a time component.  When you are not in edit mode in the cell, it shows the 12:00:00 AM part, which I don't want.

                                            <telerik:GridViewDataColumn DataMemberBinding="{Binding ReportDate}"
                                                                        EditTriggers="CellClick"
                                                                        Header="Shift Date"
                                                                        IsReadOnlyBinding="{Binding IsRowReadOnly}">
                                                <telerik:GridViewDataColumn.CellEditTemplate>
                                                    <DataTemplate>
                                                        <telerik:RadDatePicker x:Name="rdpShiftDate"
                                                                               DisplayDateEnd="{Binding DateRangeEnd}"
                                                                               DisplayDateStart="{Binding DateRangeStart}"
                                                                               InputMode="DatePicker"
                                                                               SelectedValue="{Binding ReportDate,
                                                                                                       Mode=TwoWay}" />
                                                    </DataTemplate>
                                                </telerik:GridViewDataColumn.CellEditTemplate>
                                            </telerik:GridViewDataColumn>

    I have tried doing this in the C# and it doesn't change anything:

    rdpShiftDate.Culture = new CultureInfo("en-US");
    rdpShiftDate.Culture.DateTimeFormat.ShortDatePattern = "ddd, MMM dd, yyyy";

    also tried this:

    rdpShiftDate.Culture.DateTimeFormat.ShortDatePattern = "{0:ddd, MMM dd, yyyy}";
  2. Answer
    Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 11 Oct 2012 Link to this post

    Hi Stephen,

    The properties you are setting refer only to the RadDateTimePicker in the CellEditTemplate. If you wish to edit how the column look like before you go in edit mode you have to edit the GridViewDataColumn or add a CellTemplate. In your case there is a very easy way to achieve the desired behavior just add:
    DataFormatString="{}{0:MM/dd/yyyy}"
    so your code will look something like this:
    <telerik:GridViewDataColumn DataMemberBinding="{Binding ReportDate}"
     EditTriggers="CellClick"
     DataFormatString="{}{0:MM/dd/yyyy}"
     Header="Shift Date"
     IsReadOnlyBinding="{Binding IsRowReadOnly}">


    All the best,
    Boyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Stephen
    Stephen avatar
    43 posts
    Member since:
    Apr 2012

    Posted 11 Oct 2012 Link to this post

    Excellent!  Thank you very much.
Back to Top