asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Base Types > Formatting Base Types

Formatting Base Types

Getting Started   ASP.NET Base Types


Formatting is basically the process of converting an object into a given string representation.

Often, an application may need an instance of a non-string data type to be displayed in a desired format.

Typical scenarios involve numeric and datetime objects, that often need to be presented in a predefined pattern or style, and in a manner that is relevant to a given locale.

Formatting enables developers to easily control how such objects can be rendered, the results of which can be readily customized for users in different cultures.

The following illustrates several of the various ways by which formatting is employed in typical situations.

DataRow GetChildRows Method
Run Sample | View Source
Dual Nested Templated Controls
Run Sample | View Source
Outdoor Gear
Run Sample

The first example shows using a variation of String.Format, to render the values from the UnitPrice column into a string formatted as a floating-point number with two decimal places.

The next example shows using a variation of DataBinder.Eval, to display the values from the ShippedDate column as a string in long date format.

This example also shows using the DataFormatString property of a BoundColumn in a DataGrid, to render the values from the UnitPrice column as a currency-formatted string.

The last example shows using a variation of ToString, to display the current date and time in the form Thursday, January 9, 2025.

Now let’s briefly explore some formatting essentials, to help better appreciate formatting rules and issues as we examine each of the available formatting techniques.

More ...
Back to top


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note