ComponentOne GridView for ASP.NET AJAX: GridView for ASP.NET AJAX Task-Based Help > Formatting the Grid's Content > Customizing Columns Using DataFormatString

Customizing Columns Using DataFormatString

This topic demonstrates how to customize a column using the DataFormatString property.

In the Designer

Complete the following steps to set a column's DataFormatString property in the Property builder:

1.   Right-click the C1GridView control and then click Show Smart Tag. On the C1GridView Tasks menu, click Property builder. The C1GridView Properties window appears.

2.   Select the Columns tab and choose a column in the Selected columns list. In this example, the UnitsInStock column of the Northwind Products table was selected.

3.   In the Column properties grid, set the DataFormatString property to "{0:N0} unit(s)".

 

In Source View

Switch to Source view and set the DataFormatString property by adding DataFormatString = "{0:N0} unit(s)" to a C1BoundField column definition, so it appears similar to the following:

<cc1:C1BoundField DataField="UnitsInStock" HeaderText="Stock" SortExpression="UnitsInStock" DataFormatString = "{0:N0} unit(s)">

In Code

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

      Visual Basic

' Format the UnitsInStock column.

CType(C1GridView1.Columns.ColumnByName("UnitsInStock"), C1.Web.UI.Controls.C1GridView.C1BoundField).DataFormatString = "{0:N0} unit(s)"

      C#

// Format the UnitsInStock column.

((C1.Web.UI.Controls.C1GridView.C1BoundField)C1GridView1.Columns.ColumnByName("UnitsInStock")).DataFormatString = "{0:N0} unit(s)";

 What You've Accomplished

This example formats the data in the column as numbers followed by "unit (s)":

 

 

Note that when column data type is Date, DataFormatString is set to {0:d} for displaying the date in short date. You can also set the DataFormatString property in the Columns tab of the Property builder.

* Sample Project Available

For the complete sample, see the DataFormatString sample located on the ComponentOne HelpCentral Sample page.


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