C# 如何显示第二个字符串值的格式字符串?

C# 如何显示第二个字符串值的格式字符串?,c#,html,asp.net,devexpress,C#,Html,Asp.net,Devexpress,我将两列合并为一列,即货币和价值20000美元。现在我想添加值的格式字符串,所以它将是这样的>20000美元。但是如何在第二个字符串上添加property.DisplayFormatString 我试图添加property.DisplayFormatString=0,0.00,但它没有更改格式 settings.Columns.Add(column => { column.FieldName = "Value"; column.Caption = "Total";

我将两列合并为一列,即货币和价值20000美元。现在我想添加值的格式字符串,所以它将是这样的>20000美元。但是如何在第二个字符串上添加property.DisplayFormatString

我试图添加property.DisplayFormatString=0,0.00,但它没有更改格式

settings.Columns.Add(column =>
{
    column.FieldName = "Value";
    column.Caption = "Total";
    var property = column.PropertiesEdit as TextBoxProperties;

    column.SetDataItemTemplateContent(t =>
    {
        Html.DevExpress().Label(
        l => {
              l.Text = String.Format("{0} {1}", 
                  DataBinder.Eval(t.DataItem, "CurrencyCode"), 
                  DataBinder.Eval(t.DataItem, "Value"));
            property.DisplayFormatString = {"0,0.00"}
        }).Render();
    });
});
我预计该项目的产出将是

20000美元

但实际产出是

20000美元


您可以在string.Format中应用格式设置,使用格式字符串{1:0,0.00}


这将显示为20000.0。如果不需要小数,可以尝试{1:0,0},它应该显示20000。

您应该将货币格式更改为数据库,而不是像这样在aspx页面中获取记录


从TableName中选择Name,FORMATTotalAmount,,,0。您可以使用类似c的货币格式

c表示整数货币,如2000年

c2表示十进制或浮点数,如2000.00

c3表示十进制或浮点数,如2000.000

有关更多详细信息,您可以查看本文

 l.Text = String.Format("{0} {1:0,0.00}", 
              DataBinder.Eval(t.DataItem, "CurrencyCode"), 
              DataBinder.Eval(t.DataItem, "Value"));