Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i actually want to download pdf file that contain pid, and month from january to december. the month contain float number which has 9number after coma, so it makes the griedview wider than what it should be. and when i i download the pdf file, inside the file shows error 'System.Web.UI.HtmlTextWriter'

what is actually happen here??

below is my code

C#
connection.Open();
    SqlCommand dm = new SqlCommand("select id,sum (case when [Month] = 1 then demand else 0.0 end) January, sum(case when [Month] = 2 then demand  else 0.0 end) February,sum(case when [Month] = 3 then demand  else 0.0 end) March ,sum(case when [Month] = 4 then demand  else 0.0 end) April ,sum(case when [Month] = 5 then demand  else 0.0 end) May ,sum(case when [Month] = 6 then demand  else 0.0 end) June ,sum(case when [Month] = 7 then demand  else 0.0 end) July ,sum(case when [Month] = 8 then demand  else 0.0 end) August ,sum(case when [Month] = 9 then demand  else 0.0 end) September ,sum(case when [Month] = 10 then demand  else 0.0 end) October ,sum(case when [Month] = 11 then demand  else 0.0 end) November ,sum(case when [Month] = 12 then demand  else 0.0 end) December from reorder group by id", connection);
    SqlDataReader fdm = dm.ExecuteReader();

    if (fdm.HasRows)
    {
        fdm.Read();
        GridView3.DataSource = fdm;

    }
    connection.Close();

    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=Demand.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter wsfdm = new StringWriter();
    HtmlTextWriter fdmws = new HtmlTextWriter(wsfdm);
    GridView3.AllowPaging = false;
    GridView3.RenderControl(fdmws);
    GridView3.HeaderRow.Style.Add("width", "20%");
    GridView3.HeaderRow.Style.Add("font-size", "8x");
    GridView3.Style.Add("text-decoration", "none");
    GridView3.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
    GridView3.Style.Add("font-size", "8px");

    StringReader fgdm = new StringReader(fdmws.ToString());
    Document documentpdf = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(documentpdf);
    PdfWriter.GetInstance(documentpdf, Response.OutputStream);
    documentpdf.Open();
    htmlparser.Parse(fgdm);
    documentpdf.Close();
    Response.Write(documentpdf);
    Response.End();
}
Posted

1 solution

you need to call the DataBind method
C#
fdm.Read();
GridView3.DataSource = fdm;
GridView3.DataBind();
 
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