包含gridview的pdf文件中的错误 [英] errors in pdf file that contain gridview

查看:68
本文介绍了包含gridview的pdf文件中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上想要下载包含pid的pdf文件,以及从1月到12月的月份。这个月包含浮点数,它在昏迷后有9个数字,所以它使得griedview比它应该更宽。当我下载pdf文件时,文件里面显示错误'System.Web.UI.HtmlTextWriter'



这里实际发生了什么?



以下是我的代码



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

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();
}

推荐答案

您需要调用 DataBind 方法

you need to call the DataBind method
fdm.Read();
GridView3.DataSource = fdm;
GridView3.DataBind();


这篇关于包含gridview的pdf文件中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆