ListControl.DataTextFormatString 属性


获取或设置格式化字符串,该字符串用来控制如何显示绑定到列表控件的数据。Gets or sets the formatting string used to control how data bound to the list control is displayed.

 virtual property System::String ^ DataTextFormatString { System::String ^ get(); void set(System::String ^ value); };
public virtual string DataTextFormatString { get; set; }
member this.DataTextFormatString : string with get, set
Public Overridable Property DataTextFormatString As String


绑定到控件的数据的格式化字符串。The formatting string for data bound to the control. 默认值为 EmptyThe default value is Empty.



DataTextFormatString使用属性可为列表控件中的项提供自定义的显示格式。Use the DataTextFormatString property to provide a custom display format the items in a list control.

数据格式字符串由以冒号分隔的两部分组成,格式为 { ABxx }。The data format string consists of two parts, separated by a colon, in the form { A : Bxx }. 例如,格式化字符串{0:F2}将设置单元格的格式,以显示具有两个小数位的固定的点号。For example, the formatting string {0:F2} would format the cell to display a fixed point number with two decimal places.


整个字符串必须括在大括号中,以指示它是格式字符串而不是文本字符串。The entire string must be enclosed in braces to indicate that it is a format string and not a literal string. 大括号外的任何文本都显示为文本。Any text outside the braces is displayed as literal text.

冒号前面的值(A在常规示例中)指定从零开始的参数列表中的参数索引。The value before the colon (A in the general example) specifies the parameter index in a zero-based list of parameters.


此值只能设置为0,因为每个单元格中只有一个值。This value can only be set to 0 because there is only one value in each cell.

冒号后面的字符(B在常规示例中)指定在中显示值的格式。The character after the colon (B in the general example) specifies the format to display the value in. 下表列出了常见格式。The following table lists the common formats.

格式字符Format character 说明Description
C 以货币格式显示数值。Displays numeric values in currency format.
D 以十进制格式显示数值。Displays numeric values in decimal format.
E 显示采用科学(指数)格式的数字值。Displays numeric values in scientific (exponential) format.
F 以固定格式显示数值。Displays numeric values in fixed format.
G 以常规格式显示数值。Displays numeric values in general format.
N 以数字格式显示数值。Displays numeric values in number format.
X 以十六进制格式显示数值。Displays numeric values in hexadecimal format.


格式字符不区分大小写,但除外X,后者在指定的情况下显示十六进制字符。The format character is not case-sensitive, except for X, which displays the hexadecimal characters in the case specified.

格式字符后的值(xx在常规示例中)指定要显示的有效位数或小数位数。The value after the format character (xx in the general example) specifies the number of significant digits or decimal places to display.

下表包含设置字符串格式和结果的示例。The following table contains examples of formatting strings and the results. 它采用标准的英语设置。It assumes standard English settings.

数值Numeric Value 格式字符串Format String 结果Result
12345.678912345.6789 “{0:C}”"{0:C}" $12,345.68$12,345.68
-12345.6789-12345.6789 “{0:C}”"{0:C}" ($12,345.68)($12,345.68)
1234512345 “{0:D}”"{0:D}" 1234512345
1234512345 “{0:D8}”"{0:D8}" 0001234500012345
12345.678912345.6789 “{0:E}”"{0:E}" 1234568E+0041234568E+004
12345.678912345.6789 “{0:E10}”"{0:E10}" 1.2345678900E+0041.2345678900E+004
12345.678912345.6789 “{0:F}”"{0:F}" 12345.6812345.68
12345.678912345.6789 “{0:F0}”"{0:F0}" 1234612346
12345.678912345.6789 “{0:G}”"{0:G}" 12345.678912345.6789
123456789123456789 “{0:G7}”"{0:G7}" 1.234568E81.234568E8
12345.678912345.6789 “{0:N}”"{0:N}" 12,345.6812,345.68
123456789123456789 “{0:N4}”"{0:N4}" 123,456,789.0000123,456,789.0000
12345.678912345.6789 "Total: {0:C}""Total: {0:C}" 总计: $12345.68Total: $12345.68

有关设置字符串格式的详细信息,请参阅格式设置类型For more information on formatting strings, see Formatting Types.

此属性的值存储在视图状态中。The value of this property is stored in view state.

无法通过主题或样式表主题设置此属性。This property cannot be set by themes or style sheet themes. 有关详细信息,请ThemeableAttribute参阅和ASP.NET 主题和外观For more information, see ThemeableAttribute and ASP.NET Themes and Skins.