Dim dt As DataTable
dt=some query
Dim GridView1 As New GridView()
GridView1.AllowPaging = False
GridView1.AutoGenerateColumns = False
GridView1.DataSource = dt
GridView1.DataBind()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=DataTable.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
GridView1.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
我需要将文本和DataTable
一起导出为PDF。我在GridView1.Columns.Count = 0
之后得到DataBind()
。在dt
中有列,但在DataBind()
之后,Columns.Count
返回0。
dt = some query.but显示count = 0