2013-10-06 76 views
1

格式化頁腳單元1天前 嗨,我有一個radgrid控件的貨幣值列,和導出使用此功能格式化貨幣細胞Telerik的radgrid控件:在OnExportCellFormatting

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

工作得很好脫穎而出,但它不會格式化作爲彙總總和值的頁腳項目。我如何將頁腳格式化爲貨幣?

回答

2

在標記(如果您正在使用AJAX控件),您可以如下定義(頁腳)彙總格式:

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

這將在顯示和輸出電網來實現。然而,您可能不想在屏幕上顯示它;在這些情況下,您可以更新導出事件處理程序中的屬性。您還應該注意,從上面的標記中可以得到一個DataFormatString屬性,它可以格式化單元格中顯示的數據。

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事件處理程序:

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}"; 
    } 
} 

我敢肯定,鑄造等上面做可以更有效地執行/正常,但上面的代碼應該是一個合理的地方開始。

相關問題