Why doesn't HtmlTextWriter render datetime column?

46 Views Asked by At

I been trying to export the stored procedure as an excel sheet, but the columns with datetime type do not render in the resulted table this is a simplified code sample

System.Web.UI.WebControls.DataGrid grid = new System.Web.UI.WebControls.DataGrid();
string fileName = "";

using (dbentities ctx = new dbentities())
{
    grid.DataSource = ctx.GetRecord().Select(x => new { x.RequestID, x.CreatedDate }).ToList();
    grid.DataBind();
    fileName = "";

    using (StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath(fileName)))
    {
        using (HtmlTextWriter hw = new HtmlTextWriter(sw))
        {
            grid.RenderControl(hw);
        }
    }
}
0

There are 0 best solutions below