Link to home
Start Free TrialLog in
Avatar of tonyedmo
tonyedmo

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of SystemExpert
SystemExpert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tonyedmo
tonyedmo

ASKER

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?