In this example we use HtmlDataCellPrepared to string format a DateTime type. Note that I do not have the explictly cast e.CellValue to DateTime.
@Html.DevExpress().GridView(
settings =>
{
settings.Name = "GridView";
settings.HtmlDataCellPrepared = (sender, e) =>
{
if (e.DataColumn.FieldName == "Day")
{
e.Cell.Text = String.Format("{0:MM/dd/yyyy}", e.CellValue);
}
};
settings.Width = Unit.Percentage(100);
settings.SettingsPager.PageSize = 32;
settings.Settings.VerticalScrollBarMode = ScrollBarMode.Visible;
settings.Settings.VerticalScrollableHeight = 350;
settings.ControlStyle.Paddings.Padding = Unit.Pixel(0);
settings.ControlStyle.Border.BorderWidth = Unit.Pixel(0);
settings.ControlStyle.BorderBottom.BorderWidth = Unit.Pixel(1);
settings.Columns.Add("FlightId");
settings.Columns[0].Caption = "Flight";
settings.Columns.Add("Day");
settings.Columns.Add("DepartureCityName");
settings.Columns[2].Caption = "Leaving";
settings.Columns.Add("DepartureTimeAndTimeZone");
settings.Columns[3].Caption = "Leaving";
settings.Columns.Add("DestinationCityName");
settings.Columns[4].Caption = "Arriving";
settings.Columns.Add("DestinationTimeAndTimeZone");
settings.Columns[5].Caption = "Arriving";
}).Bind(Model).GetHtml()
No comments:
Post a Comment