1. In order to use export to excel in dhtmlgrid. We need to download(http://dhtmlx.com/x/download/regular/grid-excel-net.zip) and add the following two library reference to the project.
2. Need to include “dhtmlxgrid_export.js” script file reference from the following location “../codebase/ext/” directory to your web page.
3. Use “toExcel” function with your dhtmlgrid. Which will expects serverside controller action url. In this action we need to define logic to download dhtmlgrid to excel.
Client Side Code:
Server Side Code:
Need to include “DHTMLX.Export.Excel” namespace to the controller.
public ActionResult ExportGridToExcel()
var generator = new ExcelWriter();
var xml = this.Request.Form["grid_xml"];
xml = this.Server.UrlDecode(xml);
var stream = generator.Generate(xml);
return File(stream.ToArray(), generator.ContentType, "grid.xlsx");
In the “grid_xml”. “grid_” will be ghtmlgrid name.