Home Export Data base to excel c# MVC
Reply: 0

Export Data base to excel c# MVC

S.QUIN
1#
S.QUIN Published in 2018-02-09 12:00:40Z

I want to export database to excel.

When i export list of model user (string with name nickname mail ...) no have problem. But when i want to export ( string and list of model) i have this error: The data source for GridView with id '' did not have any properties or attributes from which to generate columns. Ensure that your data source has content.

Example: Success

public class Visite
{
    public string Id { get; set; }
    public string name { get; set; }
}

Example: error

public class Visite
{
    public string Id { get; set; }
    public string name { get; set; }
    public IEnumerable<rttestExcel> rtexcel { get; set; }
}

Can you help me please?

Button:

<p>
@Html.ActionLink("ExtracExcel", "ExportToExcel")

           var gv = new GridView();
           gv.DataSource = allforextect;
           gv.DataBind();
           Response.ClearContent();
           Response.Buffer = true;
           Response.AddHeader("content-disposition", "attachment; filename=DemoExcel.xls");
           Response.ContentType = "application/ms-excel";
           Response.Charset = "";
           StringWriter objStringWriter = new StringWriter();
           HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter);
           gv.RenderControl(objHtmlTextWriter);
           Response.Output.Write(objStringWriter.ToString());
           Response.Flush();
           Response.End();
           return View();

dataSource of Gridview:

var allforextect = new List<ExportExcelall>()

Model:

public class ExportExcelall
{
    public Personnel pers { get; set; }
    public IEnumerable<rttestExcel>  rtexcel {get;set;}
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.29301 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO