请参阅ASPX
页面上的RadGrid的以下代码:
<telerik:GridTemplateColumn DataField="Supplier_Price" Aggregate="Sum" FooterText="Unit Price: " FilterControlAltText="Filter Supplier_Price column" HeaderText="Unit Price" SortExpression="Supplier_Price" UniqueName="Supplier_Price" DataType="System.Double" FooterAggregateFormatString="{0:c}">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "Supplier_Price", "{0:C}")%>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadNumericTextBox runat="server" ID="SupplierPriceRadNumericTextBox" Culture="ar-SA" MinValue="0" MaxValue="9999999999" Text='<%#Bind ("Supplier_Price") %>' Type="Currency" NumberFormat-DecimalSeparator="," NumberFormat-AllowRounding="true" NumberFormat-DecimalDigits="2">
<NumberFormat DecimalDigits="2" DecimalSeparator="." />
</telerik:RadNumericTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
现在我的问题是我需要从后面的代码中更改上面一列中{0:C}
的货币文化。
答案 0 :(得分:0)
我通过将<telerik:GridTemplateColumn>
更改为
<telerik:GridNumericColumn DataField="Supplier_Price" Aggregate="Sum" FooterText="Unit Price: " FilterControlAltText="Filter Supplier_Price column" HeaderText="Unit Price" SortExpression="Supplier_Price" UniqueName="Supplier_Price" DataType="System.Double" FooterAggregateFormatString="{0:c}">
</telerik:GridNumericColumn>
然后在GridNumericColumn
中修改代码隐藏中的OnPreRender
并添加以下代码:
protected void SupplierPriceRadGrid_PreRender(object sender, EventArgs e)
{
foreach (GridColumn column in SupplierPriceRadGrid.Columns)
{
if (SelectCurrencyDropDownList.SelectedItem.Value == "SAR")
{
if (column.UniqueName == "Supplier_Price")
{
(column as GridNumericColumn).DataFormatString = "{0:N2} .ر.س";
(column as GridNumericColumn).FooterAggregateFormatString = "{0:N2} .ر.س";
}
if (column.UniqueName == "Supplier_Total_Price")
{
(column as GridNumericColumn).DataFormatString = "{0:N2} .ر.س";
(column as GridNumericColumn).FooterAggregateFormatString = "{0:N2} .ر.س";
}
}
if (SelectCurrencyDropDownList.SelectedItem.Value == "USD")
{
if (column.UniqueName == "Supplier_Price")
{
(column as GridNumericColumn).DataFormatString = "$ {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "$ {0:N2}";
}
if (column.UniqueName == "Supplier_Total_Price")
{
(column as GridNumericColumn).DataFormatString = "$ {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "$ {0:N2}";
}
}
if (SelectCurrencyDropDownList.SelectedItem.Value == "EUR")
{
if (column.UniqueName == "Supplier_Price")
{
(column as GridNumericColumn).DataFormatString = "€ {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "€ {0:N2}";
}
if (column.UniqueName == "Supplier_Total_Price")
{
(column as GridNumericColumn).DataFormatString = "€ {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "€ {0:N2}";
}
}
if (SelectCurrencyDropDownList.SelectedItem.Value == "GBP")
{
if (column.UniqueName == "Supplier_Price")
{
(column as GridNumericColumn).DataFormatString = "£ {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "£ {0:N2}";
}
if (column.UniqueName == "Supplier_Total_Price")
{
(column as GridNumericColumn).DataFormatString = "£ {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "£ {0:N2}";
}
}
if (SelectCurrencyDropDownList.SelectedItem.Value == "CNY")
{
if (column.UniqueName == "Supplier_Price")
{
(column as GridNumericColumn).DataFormatString = "元 {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "元 {0:N2}";
}
if (column.UniqueName == "Supplier_Total_Price")
{
(column as GridNumericColumn).DataFormatString = "元 {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "元 {0:N2}";
}
}
if (SelectCurrencyDropDownList.SelectedItem.Value == "JPY")
{
if (column.UniqueName == "Supplier_Price")
{
(column as GridNumericColumn).DataFormatString = "¥ {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "¥ {0:N2}";
}
if (column.UniqueName == "Supplier_Total_Price")
{
(column as GridNumericColumn).DataFormatString = "¥ {0:N2}";
(column as GridNumericColumn).FooterAggregateFormatString = "¥ {0:N2}";
}
}
}
}
SelectCurrencyDropDownList.SelectedItem.Value == "JPY"
基本上是dropdownlist
,用户选择货币,OnPreRender
点火,一切正常!