This tutorial will show you how to export GridView to txt using ASP.NET 2.0 and VB.
First, you need to import the namespace from System.Data.SqlClient.

The System.Data.SqlClient namespace contains The System.Data.SqlClient namespace is the .NET Framework Data Provider for SQL Server.The .NET Framework Data Provider for SQL Server describes a collection of classes used to access a SQL Server database in the managed space. In tutorial, we need “AddHeader” and “ContentType” to do the work.The AddHeader method adds a new HTML header and value to the response sent to the client. It does not replace an existing header of the same name. After a header has been added, it cannot be removed. The ContentType property specifies the HTTP content type for the response. If no ContentType is specified, the default is text/HTML.

We use the Button1_Click event to do the work. We then call “Response.AddHeader” to export a file which is named FileName.txt. We then use “Response.ContentType” to denotes the type of the file being exported.

The front end GridViewExportTxtVB.aspx page looks something like this:
[asp]



[/vb]

The flow for the code behind page is as follows.

Download Source Files