You must Sign In to post a response.
  • Category: ASP.NET

    Export gridview to excel using javascript?

    How to export gridview to excel using Javascript without using Active X control???

    If it is not possible, can u give me reason??
  • #749029
    Yes it is possible , first bind your data in HTML table or Div then you can export it ,Refer these links.


    Nirav Prabtani (Senior Web Developer)
    Email :
    blog :

  • #749036
    It is a bad idea to export data to an Excel file using this method. It will export to older format of Excel.

    Bind all GridView data to DIV and then extract the contents of the DIV element using JQuery.
    Check this.

    Finally export the data to an Excel file using this JQuery procedure.

    $(document).ready(function() {
    $('#ExportData').click(function(e) {'data:application/,' + $('#showChild').html());


    Hope this helps.

  • #749069
    if you don't want to use 'ActiveXcontrol' then you can go for JQuery, following link will help you export the content of gridview to excel file
    The above link contains jquery plugin to convert html table content into excel sheet. It is very simple to use. It supports not only table data also for data grids, from XML file or Json files.
    it helps to
    1. Export Data grid to excel sheet
    2. Export to excel sheet from external JSON

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #749074

    You can achieve this as prasad explained above. But why don't you give a try using simple .NET have very good features for microsoft related stuffs. using simple controls you can achieve this. Below is the code for importing a grid in excel-
    Response.Buffer = true;
    Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "demo.xls"));
    Response.ContentType = "application/ms-excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    gvDetails.AllowPaging = false;
    gvDetails.HeaderRow.Style.Add("background-color", "#FFFFFF");
    for (int i = 0; i < gvDetails.HeaderRow.Cells.Count; i++)
    gvDetails.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");

    Ashutosh Jha

  • #749088
    Instead of using java script better use JQuery code for export option in grid.

    here is a sample code for the same.

    $("[id$=Button1]").click(function(e) {'data:application/,' + encodeURIComponent( $('div[id$=dvdata]').html()));

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • Sign In to post your comments