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

How to change format of DatePicker in GridView

2 Answers 181 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stephen
Top achievements
Rank 1
Stephen asked on 08 Oct 2012, 04:12 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Boyan
Telerik team
answered on 11 Oct 2012, 08:15 AM
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.

0
Stephen
Top achievements
Rank 1
answered on 11 Oct 2012, 06:19 PM
Excellent!  Thank you very much.
Tags
DateTimePicker
Asked by
Stephen
Top achievements
Rank 1
Answers by
Boyan
Telerik team
Stephen
Top achievements
Rank 1
Share this question
or