0

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);
        }
    }
}
Soviut
  • 88,194
  • 49
  • 192
  • 260
Opt Prutal
  • 384
  • 4
  • 14
  • 2
    Just a tip: when implementing a `using` statement you don't need to explicitly dispose of the objects, the statement does that for you. More reading: [Using statement (C# reference)](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement) – Abbas Aug 07 '17 at 09:25
  • I know, but I think its a bad habit, I like to destroy everything manual – Opt Prutal Aug 07 '17 at 09:44
  • A bad habit is trying to manually dispose of things even though you've got a `using` statement doing it for you. – Soviut Aug 07 '17 at 09:49
  • Are the id's getting rendered correctly? What if you add the datagrid to a html page.. does it show correctly? – Arcturus Aug 07 '17 at 10:10
  • Yes The id are rendering correctly – Opt Prutal Aug 07 '17 at 11:13

0 Answers0