日期:2009-01-22  浏览次数:20488 次

1.打开开始菜单
2.选择程序中的Microsoft .NET FrameWork
3.选择Documention
4.选择Index选项卡

5.输入“DataFormatString property”
6.双出出现的第一个关键词。
7.以下出现内容:
   .NET Framework Class Library   

BoundColumn.DataFormatString PropertySee Also
BoundColumn Class | BoundColumn Members | System.Web.UI.WebControls Namespace | String.Empty | DataGrid | Formatting Overview
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP
Language
C#

C++

JScript

Visual Basic

Show All

This is preliminary documentation and subject to change.
Send feedback on this topic.


Gets or sets the string that specifies the display format for items in the column.

[Visual Basic]
Overridable Public Property DataFormatString As String
[C#]
public virtual string DataFormatString {get; set;}
[C++]
public: __property virtual String* get_DataFormatString();
public: __property virtual void set_DataFormatString(String*);
[JScript]
public   function get DataFormatString() : String;
public function set DataFormatString(String);
Property Value
A formatting string that specifies the display format of items in the column. The default value is String.Empty.

Remarks
Use the DataFormatString property to provide a custom format for the items in the column.

The data format string consists of two parts, separated by a colon, in the form {A:Bxx}. For example, the formatting string, {0:D2}, would format the cell to display a number with two decimal places.

Note   The entire string must be enclosed in curly braces to denote that it is a format string and not a literal string. Any text outside the curly braces is displayed as literal text.
The value before the colon ( A in the general example) specifies the parameter index in a zero-based list of parameters.

Note   This value can only be set to 0 because there is only one value in each cell.
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.

Note   The format character is not case-sensitive, except for X, which displays the hexadecimal characters in the case specified.
The value after the format character ( xx in the general example) specifies the number of significant digits or decimal places to display the value in.

For more information on formatting strings, see Formatting Overview.

Example
[Visual Basic, C#] The following example demonstrates how to use the DataFormatString property to specify currency format for the column that displays the prices in of the DataGrid control.

[C#]
<%@ Import Namespace="System.Data" %>

<HTML>
   <script language="C#" runat="server">

      ICollection CreateDataSource()
      {
         DataTable dt = new DataTable();
  &nbs