Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a gridview that has 2 columns that are a dropdownlist and upload control. I am trying to export the gridview to excel and the code works but it only works to export the current view not all the pages. When I try to export all pages the data binding fails and code crashes. Please help if you know a way of getting all the pages exported to excel/csv with or without the columns containing controls. Thank you! Amilah
Here is my code:
C#
protected void ExportBtn_Click(object sender, ImageClickEventArgs e)
    {
        
        gv.Columns[7].Visible = false;
        gv.Columns[8].Visible = false;
        
        Response.ClearContent();
        Response.AppendHeader("content-disposition", "attachment; filename=Documents.xls");
        Response.ContentType = "application/excel";
        gv.AllowPaging = false;
        gv.DataBind();

        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
                
        Response.Charset = String.Empty;

        gv.RenderControl(htw);
        Response.Write(sw.ToString());
        
        Response.End();
    }
Posted
Updated 10-Jun-15 4:26am
v2
Comments
ramyajaya 10-Jun-15 20:20pm    
Refer this http://www.c-sharpcorner.com/uploadfile/eb5fab/export-large-data-from-gridview-to-excel-file-using-C-Sharp/

1 solution

Thank you! I found a work around by duplicating the gridview without the trouble columns and exporting it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900