Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 将gridview模板字段转换为pdf iTextSharp_Asp.net_Vb.net_Gridview_Itextsharp_Templatefield - Fatal编程技术网

Asp.net 将gridview模板字段转换为pdf iTextSharp

Asp.net 将gridview模板字段转换为pdf iTextSharp,asp.net,vb.net,gridview,itextsharp,templatefield,Asp.net,Vb.net,Gridview,Itextsharp,Templatefield,我有一个GridView,它是从DB(不是SqlDataSource之类的)编程填充的。当我格式化文本时,有4列是模板字段。它们是日期和时间,这是它们的模板字段之一: <ItemTemplate> <asp:Label ID="Label1" Text='<%# FormatDate(Eval("tDate")) %>' runat="server"></asp:Label> </ItemTemplate> Dim s As

我有一个GridView,它是从DB(不是SqlDataSource之类的)编程填充的。当我格式化文本时,有4列是模板字段。它们是日期和时间,这是它们的模板字段之一:

<ItemTemplate>
     <asp:Label ID="Label1" Text='<%# FormatDate(Eval("tDate")) %>' runat="server"></asp:Label>
</ItemTemplate>
Dim s As String = CType(gvReport.Rows(rowNo).FindControl("Label1"), Label).Text
我一直在使用本文中的方法,该方法从转换为VB代码,使用iTextSharp将GridView转换为PDF

我的问题是,在将GridView数据添加到PDF(在For循环中)时,这里出现了一个空引用异常:

如果我删除这个if语句并在这里运行Else部分:

s = gvReport.Rows(rowNo).Cells(colNo).Text.Trim()
ph = New Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL))
mainTable.AddCell(ph)
这些日期/时间列在PDF中显示为空,而所有其他列显示为无问题


我对如何解决这个问题非常迷茫,在网上找不到解决方案。

虽然我无法修复我在上面跟进的解决方案,但我找到了一种从TemplateField访问数据的不同方法:

<ItemTemplate>
     <asp:Label ID="Label1" Text='<%# FormatDate(Eval("tDate")) %>' runat="server"></asp:Label>
</ItemTemplate>
Dim s As String = CType(gvReport.Rows(rowNo).FindControl("Label1"), Label).Text
这使我可以访问指定列中的数据。现在,我只需要找到一种方法,遍历该行并获得每个不同的TemplateFields,这可能涉及到修改For循环和Select Case语句