Intersoft WebGrid Documentation
Formatting Data
See Also Send comments on this topic.
Intersoft WebGrid > WebGrid Features Overview > Formatting Data

Glossary Item Box

WebGrid provides flexibility in displaying data, especially in data formatting. Often times, you need to display data in specific format in culture. WebGrid also provides this flexibility enabling you to customize the display data. You can show the data in specific format by setting DataFormatString property in WebGridColumn.

This topic contains the following sections:

Data Formatting

In edition to rich editing capability, WebGrid also provides full-featured data formatting capabilities such as masked data display and built-in validation support.

Built-in data validation and masked data display play important roles in the editing functionality. WebGrid includes a complete rewritten of .NET's data formatting feature into client side. This means that you can set any DataFormatString that is available to .NET such as "c" for currency, "d" for short date and even custom pattern such as "MM/dd/yyy" and so on. When the edit mode is activated, it will check the assigned DataFormatString and applies it to the built-in validation core function for data checking and masking.

The built-in validation is capable to validate Numeric and DateTime type precisely according to the specified CultureInfo and default international standards. For instances, when CultureInfo is set to English and the DataFormatString is set to "yyyy-MM-dd" for DateTime column, following input is properly parsed and validated:

Input Description
07/20/2003 Valid, meet CultureInfo's DateTime format.
07/20/03 or 07 20 03 Valid, meet CultureInfo's DateTime format.
July 20, 2003 Valid, meet CultureInfo's DateTime format.
Sunday, July 20, 2003 Valid, meet CultureInfo's DateTime format.
07/20/03 13:50 Valid, meet CultureInfo's DateTime format.
20 July 2003 or July 20 2003 Valid, meet default custom DateTime pattern.
2003-07-20 Valid, meet specified custom DateTime format pattern.

The results of the built-in validation for the above input are valid. WebGrid will invoke the formatting core engine to transform the masked input with the final result which is "2003-07-20".

This feature also works with the numeric data types such as Int32, Decimal, and so on. The most interesting part in Numeric masked display feature is its full support on Microsoft .NET's NumericInfo custom formatting, including positive pattern, negative pattern as well as zero pattern. It supports most of standard numeric format strings such as c for Currency, d for Decimal, e for Scientific, f for Floating Point, g for General, n for Number as well as p for Percent. Moreover, it also supports all custom format strings such as 0, #, ., comma, %, E0, \, Literal as well as ;.

For instances, when CultureInfo is set to English UK and DataFormatString is set to "$##,##0.00;##,##0.000 $-;Zero" (custom pattern), following inputs are properly validated and masked.

Input Description Format Result
150000 Valid number. £150,000.00
2,250 Valid, meet CultureInfo's Number format. £2,250.00
3,750.789 Valid, meet CultureInfo's Number format. £3,750.79
£ 42500 Valid, meet CultureInfo's Number format. £42,500.00
-12750 Valid number. 12,750.000 £-
-£1,500.50 Valid, meet CultureInfo's Number format. 1,500.500 £-
0 Valid number. Zero


The validation and display masking will take place immediately after you exit from the edit mode by pressing Tab, Shift Tab, Enter, Esc or click on another cell in the same row.

With all these powerful features in shell, WebGrid will be the most powerful and sophisticated data display and manipulation solutions for ASP.NET Web development available in the market at the time it is released.

Conditional Formatting

FormatConditions is a new feature attached per table, designed to allow you easily define the conditions in Designer and apply the styles automatically when the condition is met. There are numerous methods you can use to define the criteria, target object, and more.

There are two conditions matching mode, the first is a simple mode where you specify a ColumnMember, Operator and ConditionText to match and the second is CustomConditionText where you can specify a filtering against the datamember available in your datasource. The filtering used in CustomConditionText comforts to the ADO.NET expression specification and therefore allows you to match any complex conditions.

TargetObject contains two values : Row and Cell. When Row is used (default), the FormatStyle will be applied to the entire row when the condition criteria matched. When set to Cell, you need to specify the TargetColumnMember. In this mode, the FormatStyle will only be applied to TargetColumnMember.

FormatConditions is built on top of automatic style merging architecture, so if there are more than one condition that matched in a single target-object, the FormatStyle will all be applied having the style priority following the order of the format condition.

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.