1

在我的代码中,我动态创建了一些网格视图。对于这些网格视图中的每一个,我想显示一个包含每列总数的页脚。我怎样才能做到这一点?

这是我创建网格视图的代码:

            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()
4

1 回答 1

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% 的时间里都有效。有时,如果您正在处理奇怪的绑定,您可能需要查看数据绑定事件以进行总计。总变量是全局范围的。

于 2012-12-06T15:40:18.340 回答