Two ways of handling:
1, template column: Suppose the data table field Completetime type is the time format
2. Bound columns:
DataFormatString Use notes:
stored in the database is the date time, but the page only shows the date, DataList and GridView inside can be formatted with dataformatstring, so that the data in the specified format display.
Example:
If yo
In ASP. net2.0, The dataformatstring = "{0: yyyy-mm-dd}" of the gridview does not work. SolutionNote that the red part must be set to false.
Format -- dataformatstring of Asp.net Data FormatWhen presenting 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
CopyCode The Code is as follows: // /// Single-choice button Column
/// /// /// If groupname is not set, use the ID of the gridview as the groupname
/// If datafield is not set, rowindex is used as the value.
/// Allow dataformatstring formatting
/// [Aspnethostingpermission (securityaction. Demand,
Level = aspnethostingpermissionlevel. Minimal)]
Public class radiobuttonselectfield: datacontrolfield
{
/// /// The name of the single-choice button group
This article mainly introduces C # in the ToString data type format encyclopedia, the need for friends can refer to the following
Formatting the GridView with DataFormatStringIn the GridView display data, to display the data has a lot of decimal places, just want it to show only two decimal places, in Delphi, directly with DisplayFormat, in. NET, checked a half-day MSDN, found that using dataformatstring can achieve this function, but how to set it d
Copy Code code as follows:
radio button Columns
If GroupName is not set, the ID of the GridView is used as the GroupName
If DataField is not set, use rowindex as value
Allow dataformatstring format data to be set
[AspNetHostingPermission (SecurityAction.Demand,
Level = Aspnethostingpermissionlevel.minimal)]
public class Radiobuttonselectfield:datacontrolfield
{
radio button group name, default to ClientID of GridView
[Description ("radio
).
Example of Setting data format in ASP. NET:{0: d} YY-MM-DD{0: p} % 00.00%{0: N2} 12.68{0: N0} 13{0: C2 }$ 12.68{0: d} 3/23/2003{0: t} 12:00:00 AM{0: Male; female}
Format -- dataformatstring of the DataGrid Data Format
Dataformatstring = "{0: Format String }"
If the original data is "12.34" and the format is set to {0: N1}, the output is "12.3 」
Format String data result"{0: c}" 12345.6
= "quantity" sortexpression = "quantity"Dataformatstring = "{0: d}">Datafield = "unitprice" sortexpression = "unitprice"Dataformatstring = "{0: c}">Backcolor = "darkslateblue"> Next, we will implement the master-Detail master-slave relationship in another more intuitive way. we use the order table and order detail table of the northwind database as examples to implement such an application. When you select
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,
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,
in this column is displayed in the Editable control.
| Asp.net format -- dataformatstring
When presenting 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 chanc
format ("12/31/99 "). {0: yy-MM-dd} date/datetime indicates the date (96-08-06) by year-month-Day of the number ). Read-Only: When this column is in editing mode, whether the data in this column is displayed in the Editable control. | Format-DataFormatString of asp.net data Format. When presenting 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 on
culture settings of the page or Web. config file.
{0:D}
Date/datetime
Short Date format ("12/31/99").
{0:YY-MM-DD}
Date/datetime
Date represented by the number of years-months-days (96-08-06).
Read-only
When this column is in edit mode, the data in the column is displayed in an editable control.
2006-02-22 | format--dataformatstring for ASP. NET Data format
When we present the data, we do not present the unmodified data to the con
format depends onPageCommand orWeb. configFile.
{0: D4}
Integer(It cannot be used with decimals .)
An integer is displayed in the fields with four character widths filled with zero.
{0: N2} %
Numeric
Displays the digits precise to the decimal point, followed"%".
{0: 000. 0}
Numeric/decimal
Number rounded to the decimal place. Less than three digits are filled with zero.
{0: d}
Date/datetime
Long Date Format ("Thursday
[ASP. NET] How to Use datafromatstring in the gridview
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 entity can be directly bound to the interface, but some fields need to be reformatted. For example, for the currency unit field, you must display the currency symbol and the display separator at every three places. For the date field, the database stores the date and time, however, the page is displ
-Only
When this column is in editing mode, whether the data in this column is displayed in the Editable control.
| Asp.net format -- dataformatstring
When presenting 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
the GridView and select "AUTO FORMAT" from the pop-up menu to select the GridView style, with many styles in it, as shown in the following figure:
If you want to customize the format for each column in the GridView, just click on the "smart tag" smart tag in the top right-hand corner of the GridView, select "Edit Columns" in the pop-up menu, and the form below will pop up, so you can set the details for each column:
For example, if you want a column to be set to a special format, and
namespace provides a built-in format property for the validation attribute set. We have applied the enumeration values for the release date and Price fields DataType . The following code example has the ReleaseDate and Price properties associated with the property DisplayFormat .[DataType (Datatype.date)] public DateTime releasedate {get; set;} [DataType (datatype.currency)] public decimal price {get; set;}DataTypeProperties are not validation attributes, and they are used to tell the view engi
With no null
, why set the dataformatstring has no effect. Do not ignore the two important attributes of BoundField HTMLEncode and Applyformatineditmode. HtmlEncode The BoundField used by the GridView differs from the DataGrid using BoundColumn, Bounfield provides a HtmlEncode attribute that provides HTML encoding of the data and reduces the BoundColumn potential HTML script embedded attack, the default value is enabled. If you want to use formatte
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.