我有一个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.有没有办法用自定义聚合或任何其他方式执行此操作?
任何帮助都会很棒。 THX!
答案 0 :(得分:1)
我认为telerik网格中没有任何inbuild functionlity / field / column来显示运行总数,但是你可以通过计算,存储它并将其绑定到页脚模板列,在网格的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();
}
}
如果我遗失了某些内容,请告诉我。