Mark This Response as Answer -- Chandu http://www.dotnetfunda.com/images/dnfmvp.gif
<body> <form id="form1" runat="server"> <div> <table> <tr> <td align="right"> <asp:ImageButton ID="btnExcel" runat="server" ImageUrl="~/ExcelImage.jpg" onclick="btnExcel_Click" /> <%--<asp:ImageButton ID="btnWord" runat="server" ImageUrl="~/WordImage.jpg" onclick="btnWord_Click" />--%> </td> </tr> <tr> <td> <asp:GridView runat="server" ID="gvdetails" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"> <RowStyle BackColor="#EFF3FB" /> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="id" HeaderText="id" SortExpression="id" /> <asp:BoundField DataField="salary" HeaderText="salary" SortExpression="salary" /> <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EmpConnectionString %>" SelectCommand="SELECT * FROM [mytab]"></asp:SqlDataSource> </td> </tr> </table> </div> </form> </body>
public override void VerifyRenderingInServerForm(Control control) { /* Verifies that the control is rendered */ } protected void btnExcel_Click(object sender, ImageClickEventArgs e) { Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Funds tRANSFER.xls")); Response.ContentType = "application/ms-excel"; //StringWriter sw = new StringWriter(); //HtmlTextWriter htw = new HtmlTextWriter(sw); gvdetails.AllowPaging = false; gvdetails.DataBind(); Response.End(); }
Mark as Answer if it helps you Thanks&Regards Aswini Aluri
Login to post response