I am trying to format a date column to MM/dd/yyyy but reguardless of what formatting I attempt it continues to return M/d/yyyy hh:mm:ss AM.
On load of the page I set the ObjetDataSource and convert to a datatable
public static DataTable LoadGrid()
{
using (Model.Entities db = new Model.Entities())
{
List<
Model.FileDetailViewNew
> fileView = (from filing in db.FileDetailViewNews
select filing).ToList();
DataTable table = ToDataTable(fileView);
return table;
}
}
private static DataTable ToDataTable<
T
>(List<
T
> items)
{
DataTable dataTable = new DataTable(typeof(T).Name);
//Get all the properties
PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in Props)
{
//Setting column names as Property names
dataTable.Columns.Add(prop.Name);
}
foreach (T item in items)
{
var values = new object[Props.Length];
for (int i = 0; i < Props.Length; i++)
{
//inserting property values to datatable rows
values[i] = Props[i].GetValue(item, null);
}
dataTable.Rows.Add(values);
}
//put a breakpoint here and check datatable
return dataTable;
}
I then on the page set the grid to the datasource
<
asp:ObjectDataSource
ID
=
"ObjectDataSource1"
runat
=
"server"
TypeName
=
"AllFilings"
SelectMethod
=
"LoadGrid"
></
asp:ObjectDataSource
>
<
div
id
=
"load"
style
=
"display: none; color: Red"
>
<
b
> Updating filing status please wait...</
b
>
</
div
>
<
div
id
=
"status"
style
=
"color: Red"
>
</
div
>
<
telerik:RadGrid
ID
=
"gridFilings"
runat
=
"server"
PageSize
=
"20"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateColumns
=
"False"
EnableAJAX
=
"True"
DataSourceID
=
"ObjectDataSource1"
EnableAJAXLoadingTemplate
=
"True"
GridLines
=
"None"
LoadingTemplateTransparency
=
"50"
EnableLinqExpressions
=
"false"
ShowStatusBar
=
"True"
Skin
=
"Outlook"
Width
=
"98%"
ShowGroupPanel
=
"True"
>
<
ClientSettings
AllowDragToGroup
=
"True"
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
ClientSettings
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
></
PagerStyle
>
<
MasterTableView
DataKeyNames
=
"FileID"
DataSourceID
=
"ObjectDataSource1"
AllowCustomSorting
=
"true"
>
and then on the grid item
<
telerik:GridTemplateColumn
DataField
=
"DateIn"
HeaderText
=
"Date In"
SortExpression
=
"DateIn"
UniqueName
=
"DateIn"
GroupByExpression
=
"DateIn Group By DateIn"
>
<
ItemTemplate
>
<%# Eval("DateIn","{0:yyyy MMMM/dd}")%>
</
ItemTemplate
>
<
HeaderStyle
CssClass
=
"headerLeft"
/>
</
telerik:GridTemplateColumn
>
I have tried numerous different formatting styles with no success. I have also tried to change it to a DateTimeColumn and format it there and it stiil continues to show for example 6/4/2014 12:00:00 AM