hi,
i am trying to export a dynamically generated gridview to excel file,
on click an excel was generated but after opening the file there are only <div> tags inside the file,
my code is like below
<td>
<asp:Menu runat="server" ID="Export" Visible="false" DynamicHorizontalOffset="0"
StaticMenuItemStyle-Height="24px" StaticMenuItemStyle-HorizontalPadding="4px"
Orientation="Horizontal" StaticDisplayLevels="1" DynamicMenuItemStyle-VerticalPadding="4px"
StaticEnableDefaultPopOutImage="false" OnMenuItemClick="Export_MenuItemClick">
<StaticMenuItemStyle ForeColor="White" />
<StaticMenuStyle CssClass="nav_main" />
<DynamicHoverStyle CssClass="nav_main" ForeColor="White" />
<DynamicMenuItemStyle CssClass="nav_main_hover" />
<DynamicMenuItemStyle HorizontalPadding="3px" />
<Items>
<asp:MenuItem Target="_blank" Text="Excel"></asp:MenuItem>
</asp:MenuItem>
</Items>
</asp:Menu>
</td>
<div style="width:100%; overflow-y:scroll;height:500px " >
<asp:Panel ID="pnlshpRpt" ClientIDMode="Static" runat="server" Visible="false" Width="99.4%" BorderStyle="Solid" BorderColor="Maroon">
<center>
<div id="divReport" style="overflow-y: auto; height:auto;">
<asp:GridView ID="grdShipSummaryReport" runat="server" Width="99.3%" BorderColor="#CC3300" BorderStyle="Solid"
CellPadding="2" HeaderStyle-CssClass="HeaderStyle" AlternatingRowStyle-CssClass="altItemStyle" RowStyle-CssClass="grid_row" OnDataBound="grdShipSummaryReport_DataBound">
<AlternatingRowStyle CssClass="altItemStyle" />
<HeaderStyle Font-Size="10 pt" CssClass="HeaderStyle" />
<RowStyle Font-Size="11px" CssClass="ItemStyle" />
</asp:GridView>
code behind
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void Export_MenuItemClick(object sender, MenuEventArgs e)
{
string Filename = "LPDPReport" + DateTime.Now + ".xls";
Response.ClearContent();
Response.Clear();
Response.Buffer = true;
Response.ClearHeaders();
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;Filename=" + Filename);
StringWriter str = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(str);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (Convert.ToInt32(ddlShpRptType.SelectedValue.ToString()) != 22)
{
grdShipSummaryReport.AllowPaging = false;
grdShipSummaryReport.GridLines = GridLines.Both;
grdShipSummaryReport.HeaderStyle.Font.Bold = true;
grdShipSummaryReport.RenderControl(htw);
Response.Write(str.ToString());
Response.Flush();
Response.Close();
Response.End();
}
else
{
grdlpdp.AllowPaging = false;
grdlpdp.GridLines = GridLines.Both;
grdlpdp.HeaderStyle.Font.Bold = true;
grdlpdp.RenderControl(htw);
Response.Write(str.ToString());
Response.Flush();
Response.Close();
Response.End();
}
}
can someone help to find my mistake and correct