I have a problem, I want to make button,when i click them all my data in datagrid will be exported to xls file
I want it in vc#

I have found this article

private void button1_Click(object sender, EventArgs e)
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);


Error 1 The name 'Response' does not exist in the current context D:\LoginControl\Form3.cs

can You help me to do this function working

Re: .NET Framework Data Access and Storage problem with export data from datagrid to excel


I cant find anything about this how to export from dataview in win form to excell
can anybody help me

Re: .NET Framework Data Access and Storage problem with export data from datagrid to excel


This code will work only for ASP.NET application, because Response exists only in ASP.NET context. There is no direct way to do this in Windows applications, but there are several ways to accomplish it using your code

1. Use Jet OLEDB Provider. You need to create INSERT SQL statements and loop through the rows of the grid to insert records one\ by one

2. Use Microsoft Office Tools for .NET. This way is slower, but gives you more functionality and allows formatting of the data.

3. Write code that stores data into CSV or HTML. Those formats recognized by Excel.

4. Use third party components that could provide desired functionality

Following are some links wit the samples