C# Telerik RadGrid和动态列的运行总计

C# Telerik RadGrid和动态列的运行总计,c#,asp.net,.net,telerik,radgrid,C#,Asp.net,.net,Telerik,Radgrid,我有一个RadGrid,它有一个带有动态列的数据源。我还在columncreated事件中使用以下代码对数据进行分组,并显示组页脚中列的总计: if (e.Column.ColumnType != "GridExpandColumn" & e.Column.ColumnType != "GridGroupSplitterColumn") { if (e.Column.UniqueName != "Item" && e.Column.UniqueNa

我有一个RadGrid,它有一个带有动态列的数据源。我还在columncreated事件中使用以下代码对数据进行分组,并显示组页脚中列的总计:

if (e.Column.ColumnType != "GridExpandColumn" & e.Column.ColumnType != "GridGroupSplitterColumn")
    {
        if (e.Column.UniqueName != "Item" && e.Column.UniqueName != "Width" && e.Column.UniqueName != "Type" && e.Column.UniqueName != "Balance")
        {
            ((Telerik.Web.UI.GridBoundColumn)e.Column).Groupable = true;
            ((Telerik.Web.UI.GridBoundColumn)e.Column).DataFormatString = "{0:N0}";
            ((Telerik.Web.UI.GridBoundColumn)e.Column).Aggregate = Telerik.Web.UI.GridAggregateFunction.Sum;
        }
    }
我的客户希望分组的页脚总数是一个运行总数。即,如果第一个总数为100,第二个总数为25,则第二个总数的页脚中的总数应显示为75。有没有一种方法可以通过自定义聚合或任何其他方式实现这一点


任何帮助都会很好。谢谢

我认为telerik网格中没有任何内置函数性/字段/列来显示running total,但是您可以在网格的ItemDataBound事件中通过计算、存储并将其绑定到页脚模板列来实现这一点,下面是示例代码:

protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        string payment = dataItem["PaymentAmount"].Text;
        decimal fieldValue = decimal.Parse(payment);
        total += fieldValue;
        dataItem["Balance"].Text = total.ToString();
    }

    if (e.Item is GridFooterItem)
    {
        GridFooterItem footerItem = e.Item as GridFooterItem;
        footerItem["PaymentAmount"].Text = "total: " + total.ToString();
    }
}

如果我遗漏了什么,请告诉我。

我使用的是动态列,因此有1到n列。我可以使用上面的代码获得页脚中的列总数,但不确定在可能有1到n列时如何运行表,因此我不能使用它们的列名。