我在ASP.NET中使用ITextSharp生成PDF。我需要显示一个表,一些数据和序列号自动递增。我尝试了以下(使用循环 - 增量),但它似乎不起作用。
Dim dsGetStudentFeeDetails = dbl.usp_GetFeeReceiptDetailsForStudent(sid).AsQueryable
For Each f1 In dsGetStudentFeeDetails
Dim i As Integer = 1
stuName = New PdfPCell(FormatPhrase(i))
'stuName.Colspan = 4
'stuName.Border = 0
stuName.NoWrap = True
stuName.HorizontalAlignment = Element.ALIGN_LEFT
pdftable4.AddCell(stuName)
stuName = New PdfPCell(FormatPhrase(f1.FeeAmountPaidDate))
'stuName.Colspan = 4
'stuName.Border = 0
stuName.NoWrap = True
stuName.HorizontalAlignment = Element.ALIGN_LEFT
pdftable4.AddCell(stuName)
i = i + 1
Next
当我在执行期间执行此操作时,我注意到i = i + 1
没有增加。为什么这样?
答案 0 :(得分:1)
你必须声明并设置默认值以上代码
下面的循环使用Dim dsGetStudentFeeDetails = dbl.usp_GetFeeReceiptDetailsForStudent(sid).AsQueryable
Dim i As Integer = 1
For Each f1 In dsGetStudentFeeDetails
stuName = New PdfPCell(FormatPhrase(i))
'stuName.Colspan = 4
'stuName.Border = 0
stuName.NoWrap = True
stuName.HorizontalAlignment = Element.ALIGN_LEFT
pdftable4.AddCell(stuName)
stuName = New PdfPCell(FormatPhrase(f1.FeeAmountPaidDate))
'stuName.Colspan = 4
'stuName.Border = 0
stuName.NoWrap = True
stuName.HorizontalAlignment = Element.ALIGN_LEFT
pdftable4.AddCell(stuName)
i = i + 1
Next