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

Split DateTime Column into two lines

2 Answers 154 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Zurab
Top achievements
Rank 1
Zurab asked on 11 Oct 2019, 12:08 PM
Is it possible to split DateTime column value with FormatString as {0:MM/dd/yyyy} \Newline {0:hh:mm:ss}?

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Oct 2019, 01:37 PM
Hello, Zurab,      

The easiest way to split the DateTime values in the grid cells is to handle the CellFormatting event and split the text as follows: 
        DateTime dt;

        private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.Row is GridViewDataRowInfo && e.Column is GridViewDateTimeColumn)
            {
                dt = (DateTime)e.CellElement.Value;
                if (dt != null)
                {
                    e.CellElement.Text = string.Format("{0:MM/dd/yyyy}", dt) + Environment.NewLine + string.Format("{0:hh:mm:ss}", dt);
                }
            }
        }


I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Zurab
Top achievements
Rank 1
answered on 15 Oct 2019, 05:36 AM

It's works fine.

Thank you.

Tags
GridView
Asked by
Zurab
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Zurab
Top achievements
Rank 1
Share this question
or