GridViewBoundField.DataFormatString属性
来源:互联网 发布:呼叫死软件 编辑:程序博客网 时间:2024/05/19 13:22
价格:{0:¥#,##0.00} 获取或设置字符串,该字符串指定字段值的显示格式。 命名空间:System.Web.UI.WebControls 语法 Visual Basic(声明) Public Overridable Property DataFormatString As String Visual Basic(用法) Dim instance As BoundField Dim value As String value = instance.DataFormatString instance.DataFormatString = value C# public virtual string DataFormatString { get; set; } C++ public: virtual property String^ DataFormatString { String^ get (); void set (String^ value); } J# /** @property */ public String get_DataFormatString () /** @property */ public void set_DataFormatString (String value) JScript public function get DataFormatString () : String public function set DataFormatString (value : String) 属性值 指定字段值的显示格式的格式化字符串。默认值为空字符串 (""),表示尚无特殊格式设置应用于该字段值。 备注 使用 DataFormatString 属性为 BoundField 对象中显示的值指定自定义显示格式。如果未设置 DataFormatString 属性,则字段的值在显示时不使用任何特殊的格式设置。默认情况下,只有当包含 BoundField 对象的数据绑定控件处于只读模式时,格式化字符串才应用到字段值。若要在编辑模式中将格式化字符串应用到字段值,请将 ApplyFormatInEditMode 属性设置为 true。 格式化字符串可以为任意字符串,并且通常包含字段值的占位符。例如,在格式化字符串“Item Value: {0}”中,当 BoundField 对象中显示字符串时,字段的值会代替 {0} 占位符。格式化字符串的剩余部分显示为文本。 注意 如果格式化字符串不包含占位符,则来自数据源的字段值将不包含在最终显示文本中。 占位符由用冒号分隔的两部分组成并用大括号括起,格式为 {A : Bxx}。冒号前的值(常规示例中为 A)指定在从零开始的参数列表中的字段值的索引。 注意 此参数是格式化语法的一部分。因为每个单元格中只有一个字段值,所以这个值只能设置为 0。 该冒号以及冒号后面的值是可选的。冒号后的字符(常规示例中为 B)指定值的显示格式。下表列出了一些常用格式。 格式字符 说明 C 以货币格式显示数值。 D 以十进制格式显示数值。 E 以科学记数法(指数)格式显示数值。 F 以固定格式显示数值。 G 以常规格式显示数值。 N 以数字格式显示数值。 X 以十六进制格式显示数值。 注意 格式字符不区分大小写,但 X 除外,它以指定的大小写形式显示十六进制字符。 格式字符后的值(常规示例中为 xx)指定显示的值的有效位数或小数位数。例如,格式化字符串“{0:F2}”将显示带两位小数的定点数。 有关格式化字符串的更多信息,请参见格式化概述。 示例 下面的代码示例演示如何使用 DataFormatString 属性为字段值指定自定义显示格式。字段中的数值被格式化为显示四个小数位。 Visual Basic 复制代码 <%@ Page language="VB" %> <html> <body> <form runat="server"> <h3>BoundField DataField Example</h3> <asp:gridview id="DiscountsGridView" datasourceid="DiscountsSqlDataSource" autogeneratecolumns="False" runat="server"> <columns> <asp:boundfield datafield="discounttype" headertext="Discount Type"/> <asp:boundfield datafield="discount" dataformatstring="{0:F4}%" itemstyle-horizontalalign="Right" headertext="Discount"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="DiscountsSqlDataSource" selectcommand="SELECT [discounttype], [stor_id], [lowqty], [highqty], [discount] FROM [discounts]" connectionstring="<%$ ConnectionStrings:PubsConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html> C# 复制代码 <%@ Page language="C#" %> <html> <body> <form runat="server"> <h3>BoundField DataField Example</h3> <asp:gridview id="DiscountsGridView" datasourceid="DiscountsSqlDataSource" autogeneratecolumns="False" runat="server"> <columns> <asp:boundfield datafield="discounttype" headertext="Discount Type"/> <asp:boundfield datafield="discount" dataformatstring="{0:F4}%" itemstyle-horizontalalign="Right" headertext="Discount"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="DiscountsSqlDataSource" selectcommand="SELECT [discounttype], [stor_id], [lowqty], [highqty], [discount] FROM [discounts]" connectionstring="<%$ ConnectionStrings:PubsConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html> 平台 Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition .NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。 版本信息 .NET Framework 受以下版本支持:2.0 请参见 参考 BoundField 类 其他资源 格式化概述
数字:{0:0.00}
建立时间:{0:yyyy年MM月dd日 hh时mm分ss秒}
程序集:System.Web(在 system.web.dll 中)
BoundField 成员
System.Web.UI.WebControls 命名空间
BoundField.DataField 属性
BoundField.ApplyFormatInEditMode 属性
- GridViewBoundField.DataFormatString属性
- DataFormatString属性
- DataFormatString 属性
- DataFormatString 属性语法
- GridView DataFormatString属性
- GridView的DataFormatString属性
- GridView中的DataFormatString属性
- Dataformatstring属性设置(详解)
- DataFormatString属性语法介绍及解决DataFormatString无效的问题
- DataFormatString属性语法介绍及解决DataFormatString无效的问题
- DataFormatString属性语法介绍及解决DataFormatString无效的问题
- DataFormatString
- DataFormatString
- DataFormatString
- DataFormatString
- Gridview利用DataFormatString属性设置数据格式
- Gridview利用DataFormatString属性设置数据格式
- DataFormatString 属性(datagrid数据邦定)
- 写意生活 {平静+期待}
- MTK 内存管理
- ASP.NET下载文件代码
- Linux Platform Device and Driver
- GridView批量删除,自定义分页,定位页码
- GridViewBoundField.DataFormatString属性
- 文件操作 复制移动删除重命名文件文件夹(转帖)
- 文件操作 复制移动删除重命名文件文件夹(转帖)
- C# NameValueCollection集合 实例
- jquery.validate
- c_str()
- 对DUILIB重构的一些看法
- 计算机的字符编码
- VC 文件路径常用操作