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

Change Autogenerated column from DateTime to short date

1 Answer 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 30 Jun 2016, 02:28 PM

I am using a stored procedure to get a DateTable of ID (int) start date and end date (both Date Time).  The columns are autogenerated.  I want both date time fields to have just the date.  I saw in the ItemDataBound to select the columns that have DateTime, but I do not see how to change the values to just date.  I am using C#

(if (col,DateType == typeof(DateTime))

{

    item(col.?

}

Thanks

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 05 Jul 2016, 08:09 AM
Hi Jeff,

You can customize the format of the date in the ColumnCreated event for the grid. The event is raised for every column. You can check if the currently created column is a GridDateTimeColumn and set the DataFormatString property for it.


protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    if (e.Column is GridDateTimeColumn)
    {
        (e.Column as GridDateTimeColumn).DataFormatString = "{0:dd/MM/yyyy}";
    }
}


For additional information on using AutoGenerated columns in the grid you would find the following article interesting.



Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or