【发布时间】:2023-03-14 14:43:01
【问题描述】:
我需要创建表,其中所有行都在 <tbody></tbody> 内,最后一行(总和列)在 <tfoot></tfoot> 内。
我可以将DataTable 的最后一行(绑定到Repeater)放入页脚,我可以在其中定义适当的模板吗?
【问题讨论】:
标签: asp.net data-binding repeater
我需要创建表,其中所有行都在 <tbody></tbody> 内,最后一行(总和列)在 <tfoot></tfoot> 内。
我可以将DataTable 的最后一行(绑定到Repeater)放入页脚,我可以在其中定义适当的模板吗?
【问题讨论】:
标签: asp.net data-binding repeater
我建议通过转发器的ItemDataBound 中的DataTable.Compute 对列求和。
例如(VB.NET,未测试,假设有一个名为'Total'的列):
Sub R1_ItemDataBound(Sender As Object, e As RepeaterItemEventArgs)
If (e.Item.ItemType = ListItemType.Footer) Then
Dim tbl = DirectCast(DirectCast(sender, Repeater).DataSource, DataTable)
Dim total = DirectCast(tbl.Compute("Sum(Total)", Nothing), Double)
' show this value in appropriate cell/control in footer '
End If
End Sub
【讨论】: