Change Autogenerated column from DateTime to short date

2 posts, 0 answers
  1. Jeff
    Jeff avatar
    6 posts
    Member since:
    May 2016

    Posted 30 Jun Link to this post

    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

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 05 Jul Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top