Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a GridView, within that onevery row of the GridView there is a Drop Down List selected. and in other cells there are data with background color. How to export that grid view to pdf or exel...

when ever I am doing its generating the pdf along with all the option of Drop Down List..

Its the code I am using on export to pdf button click

C#
Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Vithal_Wadje.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
        GridView1.AllowPaging = true;
        GridView1.DataBind();  
Posted
Updated 4-Feb-15 1:35am
v2
Comments
CHill60 4-Feb-15 7:33am    
What have you tried?
Arkadeep De 4-Feb-15 7:50am    
I have provide the code by which I am generating the pdf

1 solution

There is a "cheat" whereby you remove the dropdown (and other controls that might do something similar) from the gridview just before calling RenderControl and replace it with just the text of the selected item.

There is an example here[^]
 
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