ComponentOne GridView for ASP.NET AJAX: GridView for ASP.NET AJAX Task-Based Help > Formatting the Grid's Content > Formatting a Column as Currency

Formatting a Column as Currency

You can easily format the display of a column in the C1GridView control. For example, in this topic you'll format the UnitPrice column of the Products table to appear as currency. For more information about customizing column formatting, see the description of the DataFormatString property.

In the Designer

Complete the following steps:

1.   Click the C1GridView control's smart tag and select Property builder in the C1GridView Tasks menu.

The C1GridView Properties dialog box will appear.

2.   Select the Columns tab in the left pane.

3.   Click the UnitPrice column in the Selected columns list.

4.   In the Column properties window, scroll down to the DataFormatString property.

5.   Click the drop-down arrow next to DataFormatString and select {0:c}.

6.   Click OK to save your settings and close the C1GridView Properties dialog box.

In Source View

Switch to Source view and add DataFormatString="{0:c}" to the <cc1:C1BoundField> tag, so it appears similar to the following:

<cc1:C1BoundField DataField="UnitPrice" GroupPos="-1" HeaderText="UnitPrice" SortExpression="UnitPrice" DataFormatString="{0:c}">

In Code

Add the following code to the Page_Load event to format the column:

      Visual Basic

' Format the UnitPrice column.

CType(C1GridView1.Columns.ColumnByName("UnitPrice"), C1.Web.UI.Controls.C1GridView.C1BoundField).DataFormatString = "{0:c}"

      C#

// Format the UnitPrice column.

((C1.Web.UI.Controls.C1GridView.C1BoundField)C1GridView1.Columns.ColumnByName("UnitPrice")).DataFormatString = "{0:c}";

 What You've Accomplished

Run your application and observe that the UnitPrice column appears formatted as currency:

 


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.