在我的代码中,我动态创建了一些网格视图。对于每个网格视图,我想显示一个包含每列总计的英尺。我怎么能这样做?
这是我创建网格视图的代码:
gv_arr(chart_count) = New GridView
gv_arr(chart_count).ID = "gv" & chart_count.ToString
gv_arr(chart_count).DataSource = dt
If statistieksoort = LnxEnum.EBIChartType.DataGridView Then 'DataGridView
gv_arr(chart_count).Visible = True
'Footer voor de totalen tonen indien nodig
gv_arr(chart_count).ShowFooter = True
Else
gv_arr(chart_count).Visible = objBichart.ShowGridView
End If
gv_arr(chart_count).DataBind()
答案 0 :(得分:0)
您需要在每个数据行的rowDataBound事件中总计您想要总计的列,然后在同一事件的页脚行中插入总计。
Protected Sub gridDetails_RowDataBound(ByVal sender As Object, ByVal e As Obout.Grid.GridRowEventArgs) Handles gridDetails.RowDataBound
If e.Row.RowType = GridRowType.DataRow Then
subTotal+= {column with subtotal value}
taxTotal += {column with tax value}
discountTotal += {column with discount value}
ElseIf e.Row.RowType = GridRowType.ColumnFooter Then
Dim totalText1 As String = String.Empty
Dim totalText2 As String = String.Empty
grandTotal = subTotal + taxTotal + discountTotal
totalText1 = "Subtotal:<br />Tax:<br />Disc / Surc:<br />Total:"
totalText2 = String.Format("{0}<br />{1}<br />{2}<br />{3}", subTotal.ToString("c"), taxTotal.ToString("c"), discountTotal.ToString("c"), grandTotal.ToString("c"))
e.Row.Cells(5).Text = totalText1
e.Row.Cells(6).Text = totalText2
End If
End Sub
我发现这项工作大约有95%的时间。有时,如果您正在处理奇怪的绑定,您可能需要查看数据绑定事件以进行总计。总变量是全局范围的。