5

i am using telerik grid in my Asp.Net MVC3 application and i want to bind a Date of format dd/mm/yyyy to one of the columns of the grid as shown below:

Html.Telerik().Grid<TestResults>()
    .Name("TestResultGrid")
    .DataKeys(keys => keys.Add(c => c.SourceProgramId))
    .Columns(columns =>
        {
            columns.Bound(c => c.OriginalSourceProgramId).Title("Original Case ID").Width("90").Visible(IsOriginalCaseIdVisible);
            columns.Bound(c => c.SourceProgramId).Title("Source Program ID").Width  ("90").Visible(!IsOriginalCaseIdVisible);
           columns.Bound(c => c.Name).Title("Name").Width("140");
            columns.Bound(c => c.Points).Title("Points").Width("50");
            columns.Bound(c => c.ProgramName).Title("Program").Width("80");
            columns.Bound(c => c.DOB).Title("Created Date").Width("80");
        })
    .DataBinding(dataBinding =>
            dataBinding.Ajax()
                .Select("_TestResutls", "Test"))
    .ClientEvents(events => events
    .OnDataBinding("Grid_onDataBinding")
    .OnDataBound("Grid_onDataBound")
    .OnRowDataBound("onRowDataBound")
    .OnRowSelect("onRowSelected"))
    .Pageable(paging => paging.PageSize(10))
    .NoRecordsTemplate("<b>No Records to display.<b>")
    .Sortable()
    .Selectable()
    .HtmlAttributes(new { @class = "grid_table" })
    .Footer(true)
    .Render();

The dataType of DOB is DateTime?. I want to display date of format dd/mm/yyyy. i could have converted it to ToString() to achieve this, But i have sorting on this column. When i sort by this column it is treating the values as string and not returning the expected results. This column is nullable and hence i cant use DOB.Date method also. Any help?

TRR
  • 1,637
  • 2
  • 26
  • 43

1 Answers1

11

You should be able to do columns.Bound(c => c.DOB).Format("{0:dd/MM/yyyy}").Title("Created Date").Width("80");

Hope that helps

Chris Surfleet
  • 2,462
  • 4
  • 28
  • 40
  • Exactly what I needed! I didn't know you could change a format method into a bound column for the grid. – Baxter Oct 10 '14 at 19:41