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

Date Format in GridViewDataColumn

0 Answers 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
raghul
Top achievements
Rank 1
raghul asked on 03 Jan 2012, 02:11 PM
Hi,
I have a date picker in the gridview and I need to format the date in that. I am able to do it perfectly. But the problem is that the format gets applied only when tab off takes place. The format which I have specified does not apply when I select the date.
In order to achieve this I have done a work around as

 <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                            Header="Est."
                                            DataFormatString="{}{0:M-dd-yyyy}" UniqueName="Unique1"
                                            />

private void pre_edit(object sender, GridViewPreparingCellForEditEventArgs e)
        {
            if (e.EditingElement != null && e.EditingElement is Telerik.Windows.Controls.RadDatePicker)
            {
                if (e.Column.UniqueName.Equals("Unique1", StringComparison.InvariantCultureIgnoreCase))
                {
                    RadDateTimePicker objRadDateTimePicker = e.EditingElement as Telerik.Windows.Controls.RadDatePicker;
                    objRadDateTimePicker.Culture = new CultureInfo("en-US")
                    {
                        DateTimeFormat = new DateTimeFormatInfo
                        {
                            ShortDatePattern = "M-dd-yyyy"
                        }
                    };
                }
            }
        }

Is there any other way of doing the same? Please help

Regards,

Raghul

No answers yet. Maybe you can help?

Tags
GridView
Asked by
raghul
Top achievements
Rank 1
Share this question
or