C# – Which control performs the type conversion:GridView or data source control

ado.netasp.netcnet

Say we data bind GridView to an ObjectDataSource control and then perform a query.

A) I realize displayed GridView fields are of type String, but does GridView also know of what type the underlying data source values are ( for particular GridView column )?

* Thus, if data source will populate GridView with bunch of integers, then these integers will have to be converted to strings, before they can be displayed in GridView. Which control will perform the conversion, GridView or ObjectDataSource/SqlDataSource control?

B) Regardless of whether GridView or ObjectDataSource performs a conversion, how is that conversion performed? Simply by calling ToString() on an object?

thanx

Best Answer

The formatting (which includes the conversion) is done by the GridView. You can see that by looking at the per-column DataFormatString property. This uses the general .NET composite formatting, see for example string.Format() or Console.Writeline(). It defaults to ToString(). But DataFormatString will accept dd-mm-yyyy for a DateTime column.