hello
i am working with jqgrid in mvc.
i want to convert my date to persian date in my table.
i am using this code for that.
this is my model code:
public OrderModel()
{
OrdersGrid = new JQGrid
{
Columns = new List<JQGridColumn>()
{
new JQGridColumn { DataField = "OrderID",
PrimaryKey = true,
Editable = false,
Width = 50 },
new JQGridColumn { DataField = "OrderDate",
Editable = true,
Width = 100,
DataType = typeof(DateTime),
DataFormatString = "{0:d}",
},
new JQGridColumn { DataField = "CustomerID",
Editable = true,
Width = 100 },
new JQGridColumn { DataField = "Freight",
Editable = true,
Width = 75 },
new JQGridColumn { DataField = "ShipName",
Editable = true,
},
new JQGridColumn { DataField = "ShipAddress",
Editable = true,
}
},
Width = Unit.Pixel(1000),
Height = Unit.Pixel(400)
};
OrdersGrid.ToolBarSettings.ShowRefreshButton = true;
}
public JQGrid OrdersGrid { get; set; }
}
}
my conversion code :
public static string ToPersianDate(this DateTime date)
{
var dateTime = new DateTime(date.Year, date.Month, date.Day, new GregorianCalendar());
var persianCalendar = new PersianCalendar();
return persianCalendar.GetYear(dateTime) + "/" +
persianCalendar.GetMonth(dateTime).ToString("00") + "/" +
persianCalendar.GetDayOfMonth(dateTime).ToString("00");
}
and this is my server side code :
public ActionResult GridDemo()
{
var gridModel = new OrderModel();
var ordersGrid = gridModel.OrdersGrid;
S/etUpGrid(ordersGrid);
var list = new List<OrderModel>();
NorthWindsDataContext ss = new NorthWindsDataContext();
gridModel = (list.Select(t => new
{
OrderID = t.OrdersGrid.OrderID,
OrderDate = t.OrderDate == null
? ""
: new PersianDateTime(t.OrderDate.Value)
.ToString(PersianDateTimeFormat.DateShortTime)
}))
.ToList();
and so Other code for convert code ...
return View(gridModel);
}
but they are not correct and that does not detect OrderDate.
how shoud i modify my code...
pls give me a sample code.
thank you so much from answer.