aspxtreme

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.

Books and more
Run Sample | View Source
DataRow GetChildRows Method
Run Sample | View Source
Dual Nested Templated Controls
Run Sample | View Source

The first example shows using a variation of ToString, to display the current date and time in the form Saturday, November 21, 2009 6:35 PM.

The next 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 last example shows using a variation of DataBinder.Eval, to display the values from the ShippedDate column as a string in long date format.

The last 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.

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.



Books and more ...


Suggested Reading

Need a break ?


More ...
Back to top

Check out related books at Amazon

© 2000-2008 Rey Nuñez All rights reserved.

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

You can help support aspxtreme