Export Gridview to Excel, too much info

I am using the following code to export a gridview into Excel:

                Response.Clear();
                Response.AddHeader("content-disposition", "attachment;filename=Alldata.xls");
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = "application/vnd.ms-excel";
                System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                GridView1.RenderControl(htmlWrite);
                Response.Write(stringWrite.ToString());
                Response.End();

On the same form that the gridview control is in there is also a couple of  dropdown list with various information.  Well when I use the above code to export the Gridview I get all the values from the dropdowns to appear on the spreadsheet too.  How do I make it so only the information from the gridview appears in the Excel spreadsheet and nothing else? Thanks.
tonyedmoAsked:
Who is Participating?
 
SystemExpertCommented:


Hi,

You can use SQL REPORTING SERVICES for export to excel,PDF ,..... and you can also  

or

private void ExportLinkButton_Click(object sender, System.EventArgs e)
{
  string strTitle = “put the grid title here”;
  new DataGridExcelExporter(this.YourGridName , this.Page).Export(strTitle);
}
where,

strTitle is the title of the DataGrid.
DataGridExcelExporter is the name of main class.
this.YourGridName is the DataGrid object.
this.Page is the current Page object.


or

 you can go for this link and find the solution

http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asp

http://www.codersource.net/published/view/283/exporting_data_grid_to_excel.aspx

Thanks
 
0
 
tonyedmoAuthor Commented:
Thanks for your help, but all these examples still don't solve my problem.  For some reason with all these examples its throwing all the information from my dropdown lists along with my gridview into an Excel Spreadsheet.  I just want the information from my gridview in the spreadsheet.  Does anybody know what is going on with that?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.