0

How can I format a price in Eval() method for a price in Danish and with currency symbol on the right i C# ?

I have the following in my .aspx page to display the price:

<td class="text-right price-col"><%# Eval("Price", "{0:c}") %></td>

But this display the price as e.g. kr. 79,00 .. what I want is 79,00 kr.

I saw this post Changing Currency Symbol location in System.Globalization.NumberFormatInfo and added this method in codebehind which gives me the result I want:

<td class="text-right price-col"><%# PriceFormat(79) %></td>

protected string PriceFormat(decimal price) {
        System.Globalization.CultureInfo danish = new System.Globalization.CultureInfo("da-DK");
        danish = (System.Globalization.CultureInfo)danish.Clone();
        // Adjust these to suit
        danish.NumberFormat.CurrencyPositivePattern = 3;
        danish.NumberFormat.CurrencyNegativePattern = 3;
        decimal value = price;
        string output = value.ToString("C", danish);

        return output;
    }

But can I use the PriceFormat method with the Eval() method to get right price as parameter or modify the format in Eval() method to do the same? I the example I just insert a static value as parameter (79).

4

1 回答 1

3

Eval 返回 an object,因此您可以将其强制转换为 adecimal并将其作为参数传递给您的PriceFormat方法:

<%# PriceFormat((decimal)Eval("Price")) %>
于 2013-07-21T14:21:49.183 回答