Hello Friends
Few days ago one of my friend told me please tell me how can i export Gridview`s data into the Excel sheet he needed in his working project.
so i m writing this post from them who need same stuff in their projects.
Create one button for the Export Excel Functionality and it`s Click event do following code.
Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
Response.Clear()
Response.AddHeader(”content-disposition”, “attachment;filename=test.xls”)
Response.ContentType = “application/vnd.xls”
Dim sw As StringWriter = New StringWriter()
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
GridView1.RenderControl(htw)
Response.Write(sw.ToString())
Response.End()
End Sub
After Create Button Code just copy and paste below code
on page
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
last change is
<%@ Page Language="VB" AutoEventWireup="true" enableEventValidation =”false” CodeFile=”Default.aspx.vb” Inherits=”_Default” %>
Make enableEventValidation =”false” on page directives.
Please post comment that code works for you or not
Thanks In Advance.
Tags: Export Gridview Data to Excel Sheet, Export Gridview Data to Excel Sheet in asp .net
Hello ! I am Arjun Jadeja a Software Engineer by Profession. You can contribute and I will distribute your ideas through this site. Thanks and Enjoy
Leave a reply