protected void btnexport_Click(object sender, EventArgs e) { string attachment = "attachment; filename=Emp.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gridreport.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }
<asp:Panel ID="Panel1" runat="server" Height="317px" ScrollBars="Both"> <asp:GridView ID="gridreport" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Height="294px" Width="418px"> <FooterStyle BackColor="White" ForeColor="#000066" /> <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /> <RowStyle ForeColor="#000066" /> <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#007DBB" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#00547E" /> </asp:GridView> </asp:Panel> </asp:Content>
<form id="form1" runat="server"></form>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)