Follow these steps

Source: Internet
Author: User
Tags empty numeric tostring
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.

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

<script language= "C #" runat= "Server" >

ICollection CreateDataSource ()
{
DataTable dt = new DataTable ();
DataRow Dr;

Dt. Columns.Add (New DataColumn ("IntegerValue", typeof (Int32));
Dt. Columns.Add (New DataColumn ("StringValue", typeof (String));
Dt. Columns.Add (New DataColumn ("Currencyvalue", typeof (Double));

for (int i = 0; i < 9; i++)
{
Dr = dt. NewRow ();

Dr[0] = i;
DR[1] = "Item" + i.tostring ();
DR[2] = 1.23 * (i + 1);

Dt. Rows.Add (DR);
}

DataView dv = new DataView (DT);
return DV;
}

void Page_Load (Object sender, EventArgs e)
{

if (! IsPostBack)
{
Need to load this data only once
Itemsgrid.datasource= CreateDataSource ();
Itemsgrid.databind ();
}
}

</script>

<body>

<form runat=server>


<b>product list</b>

<asp:datagrid id= "Itemsgrid"
Bordercolor= "BLACK"
Borderwidth= "1"
Cellpadding= "3"
Autogeneratecolumns= "false"
runat= "Server" >

</HeaderStyle>

<Columns>

<asp:boundcolumn
headertext= "Number"
datafield= "IntegerValue" >
</asp:BoundColumn>

<asp:boundcolumn
headertext= "Description"
datafield= "StringValue" >
</asp:BoundColumn>

<asp:boundcolumn
headertext= "Price"
Datafield= "Currencyvalue"
Dataformatstring= "{0:c}" >
</asp:BoundColumn>

</Columns>

</asp:DataGrid>

</form>

</body>
[Visual Basic]
<%@ Import namespace= "System.Data"%>

<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>

<form runat=server>


<b>product list</b>

<asp:datagrid id= "Itemsgrid"
Bordercolor= "BLACK"
Borderwidth= "1"
Cellpadding= "3"
Autogeneratecolumns= "false"
runat= "Server" >

</HeaderStyle>

<Columns>

<asp:boundcolumn
headertext= "Number"
datafield= "IntegerValue" >
</asp:BoundColumn>

<asp:boundcolumn
headertext= "Description"
datafield= "StringValue" >
</asp:BoundColumn>

<asp:boundcolumn
headertext= "Price"
Datafield= "Currencyvalue"
Dataformatstring= "{0:c}" >
</asp:BoundColumn>

</Columns>

</asp:DataGrid>

</form>

</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


Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.