English 中文(简体)
哪个控件执行类型转换:GridView 还是数据源控件?
原标题:
  • 时间:2009-03-22 20:16:45
  •  标签:

假设我们将 GridView 数据绑定到 ObjectDataSource 控件上,然后执行查询。

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

问题回答

格式化(包括转换)是由GridView完成的。您可以查看每列DataFormatString属性来了解此内容。这使用通用的.NET组合格式化方式,例如string.Format()或Console.Writeline()。默认为ToString()。但是,DataFormatString将接受DateTime列的dd-mm-yyyy。

這是從邊界列控制代碼(通過反射器):

 if (this.formatting.Length == 0)
 {
     return dataValue.ToString();
 }
 return string.Format(CultureInfo.CurrentCulture, this.formatting, new object[] { dataValue });
  • this.formatting: The format string, is what Henk has explained.
  • dataValue: An object variable which is the value of the bound property




相关问题
热门标签