1. Open Start Menu
2. Select the Microsoft. NET FrameWork in your program
3. Choose Documention
4. Select the Index tab
5. Enter "DataFormatString Property"
6. Double out the first keyword that appears.
7. The following content appears:
. 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, Windows NT 4.0, Windows Millennium Edition, Windows xp-based, 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 being enclosed in curly braces to denote this 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.
This value can only be set to 0 because there are 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 the fixed format.
G displays numeric values in the general format.
N displays numeric values in number format.
X displays numeric values in hexadecimal format.
Note The format character isn't case-sensitive, except for X, which displays the hexadecimal characters in the case SPE Cified.
The value after the format character (xx in the general example) specifies the number of significant digits or decimal pl Aces to display the value in.
For more information on formatting strings, and the formatting Overview.
Example
[Visual Basic, C #] The following example demonstrates the DataFormatString property to specify currency format for the column Displays the prices in the DataGrid control.
<script language= "VB" runat= "Server" >
Function CreateDataSource () as ICollection
Dim DT as New DataTable ()
Dim Dr as DataRow
Dt. Columns.Add (New DataColumn ("IntegerValue", GetType (Int32))
Dt. Columns.Add (New DataColumn ("StringValue", GetType (String))
Dt. Columns.Add (New DataColumn ("Currencyvalue", GetType (Double))
Dim I as Integer
For i = 0 to 8
Dr = dt. NewRow ()
Dr (0) = i
DR (1) = "Item" + i.tostring ()
DR (2) = 1.23 * (i + 1)
Dt. Rows.Add (DR)
Next I
Dim DV as New DataView (DT)
Return DV
End Function ' CreateDataSource
Sub Page_Load (sender as Object, E as EventArgs)
If not IsPostBack Then
' Need to load this data only once
Itemsgrid.datasource = CreateDataSource ()
Itemsgrid.databind ()
End If
End Sub ' Page_Load
</script>
<body>
</body>
[C + +, JScript] No example is available in C + + or JScript. To view a Visual Basic or C # example, click the Language Filter button in the upper-left corner of the page.
Requirements
Platforms:windows, Windows NT 4.0, Windows Millennium Edition, Windows xp-based, Windows XP
Also
BoundColumn Class | BoundColumn Members | System.Web.UI.WebControls Namespace | String.Empty | DataGrid | Formatting Overview
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.