Formatting Data

When you bind data with the DataBinder control or the DataGrid control, you can format the display of numerical, date, and boolean values. Each binding managed by a DataBinder control, and each column in a DataGrid control, has a dataFormat property that allows you to specify the format.

To access the dataFormat property

  1. If you are using a DataBinder control, expand its bindings property in the Properties window.

    -or-

    If you are using a DataGrid control, expand its columns property in the Properties window.

  2. Each binding or column is listed by its index, which specifies its order within the parent control. (The index of the first binding or column is 0.)

  3. Expand the indexed entry of the binding or column you want to format, and then click dataFormat.

To format numerical values

  1. Set the dataFormat property to NumberDataFormat.

  2. Expand dataFormat, and then set the format property to a numerical format string. For information about possible format strings, see the reference topic.

To format date (or time) values

  1. Set the dataFormat property to DateDataFormat.

  2. Expand dataFormat. To specify the date format, click the format property and select one of the following values in the drop-down list:

    Format Description
    Long The dates are formatted using the Long Date setting in the Regional Settings section of the Windows Control Panel. (The default setting for a long date appears as Monday, March 9, 1998.)
    Short (Default) The dates are formatted using the Short Date setting in the Regional Settings section of the Windows Control Panel. (The default setting for a short date appears as 3/9/98.)
    Time The times are formatted using the Long Time setting in the Regional Settings section of the Windows Control Panel. (The default setting for a long time appears as 2:45:05 PM.)
    Custom The dates or times are formatted using a custom format. Set the customFormat property to the custom format string. For information about possible format strings, see the reference topic.

    Note   The setting of the customFormat property is applied only when the format property is set to Custom. If the format property is set to Short, Long, or Time, any setting for the customFormat property is ignored.

To format boolean values

  1. Set the dataFormat property to BooleanDataFormat.

  2. Expand dataFormat and set the following properties:

    • falseValue   Specifies the string to be displayed when the value is false. The default string is False.

    • nullValue   Specifies the string to be displayed when the value is null. The default string is (null).

    • trueValue   Specifies the string to be displayed when the value is true. The default string is True.