DataFormatString is a lot of asp.net controls have properties, such as the GridView, and so on, the following briefly describes this property.
The DataFormatString property syntax is as follows:
Dataformatstring= ' {0: format string} '
We know that {0} in DataFormatString
Represents the data itself, and the format
DataFormatString is a lot of asp.net controls have properties, such as the GridView, and so on, the following briefly describes this property.
The dataformatstring property syntax is as follows:
Dataformatstring= ' {0: format string} '
We know that {0} in DataFormatString
Represents the data itself, and the format
Replace
Gridview
Controls
Boundfield
The data row is set
Dataformatstring
Attribute, but has no effect. We would like to remind you that you
Dataformatstring
To make the formatted string set in the property take effect, you must
Boundfield
The
Htmlencode
Attribute
False
(Table
1
And
2
In this way, the table can be formatted smoothly.
3
).Chart 1Chart 2 Format the gridv
When we obtain data entities from the business logic layer, the next thing is to bind them to the control. Some fields in the data object can be directly bound to the interface, but some fields need to be reformatted. For example, for the currency unit field, you need to display the currency symbol and the display separator at every three places; for example, for the date field, the database stores the date and time, however, the page is displayed in the format of xxxx, XX, and XX. In this case,
Set the DataFormatString of BoundField. Generally, the following types of DataFormatString = "{0: C}" currencies are available. The format of the currencies depends on the settings of the Culture in the current Thread. DataFormatString = "{0: e} "scientific notation DataFormatString =" {0: P} "percentage
First, set the autogeneratecolumns attribute of the gridview to false (the default value is false), and select the corresponding field in datafield, note that you must set the htmlencode attribute of the field to false. Otherwise, the format cannot be displayed, then you can set the dataformatstring attribute of each field to output different formats. The property Syntax of dataformatstring is as follows:
When we obtain data entities from the business logic layer, the next thing is to bind them to the control. Some fields in the data object can be directly bound to the interface, but some fields need to be reformatted. For example, for the currency unit field, you need to display the currency symbol and the display separator at every three places; for example, for the date field, the database stores the date and time, however, the page is displayed in the format of XXXX, XX, and XX. In this case,
The example in this article describes how the GridView uses the DataFormatString property to format data. Share to everyone for your reference, specific as follows:
First, set the AutoGenerateColumns property of the GridView to False (the default is False), DataField Select the appropriate field, especially to set the HTMLEncode property of the field you want to set to false. Otherwise, the format you set will not display, and you can set the
The following points need to be noted here1: Because 2.0 for security reasons, also set HTMLEncode = False to enable dataformatstring to take effect. Asp:boundfield in the GridView use DataFormatString must set the property htmlencode= "False", otherwise it will not work.
2: If you need to use a format string of date types, the corresponding field in the data entity should also be of the date type.
3: Forma
If you directly set dataformatstring to {0: d}, you will not see the expected results.
Set the value to false in htmlencode.
PS:
The syntax of the dataformatstring attribute is as follows:
Dataformatstring = "{0: Format String }"
We know that {0} In dataformatstring represents the data itself, while the format st
The syntax of the dataformatstring attribute is as follows:
Dataformatstring = "{0: Format String }"
We know that {0} In dataformatstring represents the data itself, while the format string after the colon represents the format that we want the data to display; in addition, after the specified format symbol, you can specify the number of digits to be displa
In the gridview and DataGrid, The dataformatstring syntax is summarized-Jack @ cnblogs-blog
String in dataformatstring formatDataformatstring = "{0: Format String }"
{0} In dataformatstring represents the data itself, while the format string after the colon represents the format they want to display the data;
Number and currency format:After the specified for
Detailed description of ASP. NET data format dataformatstring when we present data, do not present unmodified data to users. For example, if the amount is 10 thousand RMB, If we directly display "10000", the user may be treated as one thousand or 100,000, causing the user to read data. If we make the final modification of 10 thousand yuan into "NT $10,000", it will not only make reading better, but also reduce the chance of making mistakes.
The follow
In. NET, the MSDN has been checked for half a day, and it is found that using dataformatstring can implement this functionality, but how the setting does not work, and finally found that, because 2.0 for security reasons, but also to set HTMLEncode = False, can make dataformatstring effective.
Leave a mark, the next time you use, you don't have to waste more than n time. Also,
Display Data in the gridview. If the data to be displayed has multiple decimal places, you just want it to display only two decimal places. in Delphi, you can simply use displayformat. net, after checking msdn for half a day, I found that dataformatstring can be used to implement this function, but how to set it does not work. Finally, I found that because 2.0 is for security considerations, you must also set htmlencode = false to make
The syntax of the dataformatstring attribute is as follows:
Dataformatstring = "{0: Format String }"
We know that {0} In dataformatstring represents the data itself, while the format string after the colon represents the format that we want the data to display; in addition, after the specified format symbol, you can specify the number of digits to be displayed i
Format the gridview with dataformatstringDisplay Data in the gridview. If the data to be displayed has multiple decimal places, you just want it to display only two decimal places. in Delphi, you can simply use displayformat. net, after checking msdn for half a day, I found that dataformatstring can be used to implement this function, but how to set it does not work. Finally, I found that because 2.0 is for security considerations, you must also set h
format (short date + short time) mm/dd/yyyy hh:mmG General Format (short date + long time) mm/dd/yyyy HH:mm:ssM,m month-day format MMMM DDs moderate date time format Yyyy-mm-dd HH:MM:SST streamlined time format hh:mmT Verbose time Format HH:mm:ss
Public virtual stringdataformatstring {get; set;}
C++
Public:
Virtual property string^ dataformatstring {
string^ get ();
Voidset (string^ value);
}
DataFormatString is a property of many Asp. Net controls, such as the GridView. The following briefly introduces this property.The syntax of the DataFormatString attribute is as follows: DataFormatString = "{0: Format String }"We know {0} In DataFormatString}Represents the data itself, and the format string after the c
If dataformatstring is invalid, add the htmlencode = "false" attribute"---------------------------------------The syntax of the dataformatstring attribute is as follows: dataformatstring = "{0: Format String}" We know {0} In dataformatstring}
Represents the data itself, and the format string after the colon represents
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.