0

Hi i want to export the data present in my jQgrid in one of my asp.net web application into excel sheet i looked around the net and i find only sites that tell me how to do it for MVC application and this is not wat i want. I tried doing this but i am getting some error in my global.asax file.
i added a button in my web page and on click of it i am doing this.

 protected void btnExport_Click(object sender, EventArgs e)
    {            
        grdLateFeeConfiguration.ExportToExcel("BlockedUsers.xls");
    }

and i get an exception here in my global.asax file

 protected void Application_Error(object sender, EventArgs e)
    {
        Exception exception = Server.GetLastError();
        HttpException httpException = (HttpException)exception;
        int httpCode = httpException.GetHttpCode();
        Application["errorInfor"] = httpCode;

    }

The exception object that is returned by the Server.GetLasrError() method is always null and i get a null pointer exception when httpException.GetHttpCode(); i dont understand wat is happening can someone explain wat is happening.

Vishweshwar Kapse
  • 921
  • 6
  • 23
  • 43
  • Probably [the answer](http://stackoverflow.com/a/9349688/315935) provide the solution. – Oleg Jul 15 '13 at 10:32
  • i am sorry i dont understand. – Vishweshwar Kapse Jul 15 '13 at 10:35
  • 1
    [The answer](http://stackoverflow.com/a/9349688/315935) and [another one](http://stackoverflow.com/a/13957161/315935) provide the code which shows how to export data to Excel file (XLSX) from ASP.NET MVC application. [The demo project](http://www.ok-soft-gmbh.com/jqGrid/jqGridExportToExcel.zip) demonstrate it and combines displaing of data in jqGrid with exporting the data. [Another demo](http://www.ok-soft-gmbh.com/jqGrid/ExportToExcel.zip) are used as pure ASHX handler and can be used in any ASP.NET application. – Oleg Jul 15 '13 at 10:43
  • Dear @oleg i tried doing it with the method `DataForExcel(string[] headers, DataType[] colunmTypes, List data, string sheetName)` as suggested by you but i still get the same error in exactly the same location i showed above is it possible to export the data from the client side and not the server side? – Vishweshwar Kapse Jul 19 '13 at 07:54
  • Do you used my demo project? In which line you get the error? The security of web browser allows you to download from any web site Excel file and to open it directly in Microsoft Excel installed locally, but there are no JavaScript function which would allow you to create binary file (.XLSX) and to start associated program Excel. All the restrictions exists because of security reason. – Oleg Jul 19 '13 at 09:45
  • I did not get error in your code, I am getting an error in the Global.asax file Error `Message:Session state is not available in this context` – Vishweshwar Kapse Jul 19 '13 at 12:14
  • @Oleg I did not get error in your code, I am getting an error in the Global.asax file Error Message:Session state is not available in this context – Vishweshwar Kapse Jul 19 '13 at 12:39
  • Sorry, but I don't understand your implementation and I don't understand why you modified `Global.asax`. – Oleg Jul 19 '13 at 14:46
  • Hi @Oleg This problem was occurring due to the – Vishweshwar Kapse Jul 19 '13 at 15:09
  • @Oleg is it possible to format the data that is sent as a response to the export so that the data that appears in the excel sheet just as it appears in the jqgrid – Vishweshwar Kapse Jul 19 '13 at 15:34
  • The code from [the answer](http://stackoverflow.com/a/13957161/315935) which I referenced before shows how to assign `StyleIndex` property of the cell and how to define different styles. So you can produce any format like you need. – Oleg Jul 19 '13 at 15:45

1 Answers1

0

This problem was occurring due to the presence of UpdatePannel control when this was removed it worked fine.

Vishweshwar Kapse
  • 921
  • 6
  • 23
  • 43