Export Gridview to Excel, too much info

Posted on 2006-03-27
Last Modified: 2007-12-19
I am using the following code to export a gridview into Excel:

                Response.AddHeader("content-disposition", "attachment;filename=Alldata.xls");
                Response.Charset = "";
                Response.ContentType = "application/";
                System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

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.
Question by:tonyedmo
    LVL 10

    Accepted Solution



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


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

    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.


     you can go for this link and find the solution


    Author Comment

    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?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now