Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How to export to XLS from Gridview View modes: 
User avatar
Member
Member
Oli Jeffery - 1/19/2011 3:00:40 AM
   
How to export to XLS from Gridview
Not a question, more of a quick bit of knowledge sharing, but as an asp.net novice, it took me ages to figure this out and I though similar newbs might appreciate the solution.

To export a Gridview webpart from Kentico into an .xls file, just put the following code into the layout of the template you're using:


<cc1:CMSWebPartZone ID="zoneCenter" runat="server" />


<%

Response.AppendHeader("content-disposition", "attachment; filename=Export.xls");
Response.ContentType = "application/vnd.ms-excel";
Response.Flush();
Response.End();

%>


and pop a Grid View web part into the WebPartZone you've declared.

When you load this page, a Save/Open dialogue will appear (or whatever the equivalent is on the browser you're using) and you can export your data.

Obviously, this is the simplest layout possible, and can be customised to your actual layout. Also, the mime type can be messed around with to get other formats, but this is the only one I've tested.