1

I would like to define globally a couple of standard format strings for numbers to be used across my ASP.NET project to format number on ASPxGridViews.

What I would like is to define somewhere something like:

 public static String defaultQuantyFormat="#,#.00000"
 public static String defaultAmountFormat="#,#.00"

Then to have in my aspx code:

<dx:ASPxGridView ID="StrategyObjectsGridView" runat="server">
    <Columns>
        <dx:GridViewDataTextColumn FieldName="quantity" DisplayFormatString='<%# defaultQuantyFormat %>'>
        <dx:GridViewDataTextColumn FieldName="amount" DisplayFormatString='<%# defaultAmountFormat %>'>
    </Columns>
</dx:ASPxGridView>

Is it possible to do something like that?

berserck
  • 499
  • 4
  • 19
  • what do you mean by globally? – Jodrell Dec 12 '14 at 14:32
  • I mean centrally, I define the string in one place, and them use it in all my pages, ensuring uniformity in the format across the project, and if I want to change the format there is a single point to change, and the format will change everywhere. – berserck Dec 15 '14 at 08:14

2 Answers2

1

Stick them in a class, make the namespace the same as the rest of the project...

public class MyClass
{
    public const string _DefaultQuantityFormat = "#,#.0000";
}

Then in your page

DisplayFormatString='<%# MyClass._DefaultQuantityFormat %>'
Hugo Yates
  • 2,081
  • 2
  • 26
  • 24
  • This solution does not work, when I try it I get the error: Parser Error Message: Databinding expressions are only supported on objects that have a DataBinding event. DevExpress.Web.ASPxEditors.TextBoxProperties does not have a DataBinding event. Source Error: `Line 153: Same is true for the solution from @Igor – berserck Dec 15 '14 at 08:47
  • Ok thought you'd sorted that as you were databinding in your example. Try this: http://stackoverflow.com/questions/11725752/aspxgridview-itemplate-and-eval – Hugo Yates Dec 15 '14 at 12:52
1

In code:

namespace Application.Settings
{
  public class FormatSettings
  {
    public const string DefaultQuanty="#,#.00000"
    public const string DefaultAmount="#,#.00"
  }
}

In markup:

<%@ Import NameSpace="Application.Settings" %>

...

<dx:GridViewDataTextColumn FieldName="quantity" 
  DisplayFormatString='<%# FormatSettings.DefaultQuanty %>'/>
Igor
  • 15,833
  • 1
  • 27
  • 32