Telerik RadGrid:在 OnExportCellFormatting 中格式化页脚单元格 [英] Telerik RadGrid: Formatting Footer cell in OnExportCellFormatting

查看:44
本文介绍了Telerik RadGrid:在 OnExportCellFormatting 中格式化页脚单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发表于 1 天前我在 radgrid 中有一个货币值列,并使用此函数导出到 excel 以格式化货币单元

Posted 1 day ago Hi, I have a currency value column in a radgrid, and exporting to excel using this function for formatting the currency cells

protected void RadGrid_OnExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
    if (e.FormattedColumn.DataType == typeof (long))
    {
        e.Cell.Style["mso-number-format"] = "Currency";
    }
}

效果很好,但它没有格式化作为聚合总和值的页脚项目.如何将页脚格式化为货币?

Works very well, but it doesn't format the footer item which is an aggregated sum value. How do I format the footer to be currency as well?

推荐答案

在标记中(如果您使用的是 AJAX 控件)您可以定义(页脚)聚合格式如下:

In the markup (if you are using the AJAX controls) you can define the (footer) aggregate format as follows:

<telerik:GridBoundColumn DataField="columnName" HeaderText="Money" UniqueName="uniqueColumnName"  
    DataFormatString="{0:C}" Aggregate="Sum" FooterAggregateFormatString="{0:C}" />

这将在显示和导出的网格上实现.但是,您可能不想在屏幕上显示它;在这些情况下,您可以从导出事件处理程序中更新属性.您还应该注意到,上面的标记有一个 DataFormatString 属性,它可以格式化单元格中显示的数据.

This will be implemented on the displayed and exported grid. It is however possible that you do not want to display this on the screen; in these instances you could update the attribute from within an export event handler. You should also note that from the above markup there is a DataFormatString attribute which can format the data displayed in the cell.

protected void RadGrid_OnExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
    if ((e.FormattedColumn.DataType == typeof(long))) {
        e.Cell.Style("mso-number-format") = "Currency";
        if (((e.FormattedColumn) is GridBoundColumn)) {
            GridBoundColumn col = e.FormattedColumn;
            col.FooterAggregateFormatString = "{0:C}";
        }
    }
} 

否则,您可以使用 GridExporting 事件处理程序执行此操作:

You could otherwise do this with a GridExporting event handler:

protected void RadGrid_GridExporting(object sender, GridExportingArgs e)
{
    GridColumn gridCol = grdCustomers.MasterTableView.GetColumnSafe("uniqueColumnName");
    if (((gridCol) is GridBoundColumn)) {
        GridBoundColumn boundCol = (GridBoundColumn)gridCol;
        boundCol.FooterAggregateFormatString = "{0:C}";
    }
}

我确信上面完成的转换等可以更有效/正确地实现,但上面的代码应该是一个合理的起点.

I'm sure the casting etc. done above could be implemented more efficiently/properly, but the above code should be a reasonable place to start from.

这篇关于Telerik RadGrid:在 OnExportCellFormatting 中格式化页脚单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆