惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 小小小程序员

转 ASP.NET 2.0中OWC生成柱状图和饼状图的源代码 - 小小小程序员 同一个ASP站点UTF-8和GB2312的两个子站点乱码的解决方法 - 小小小程序员 转 ASP.NET 页面事件执行顺序 转 用 Javascript 验证表单(form)中的单选(radio)值 - 小小小程序员 转 .net里如何判断中文字符长度 转CSDN Sybase PowerDesigner专区 转 ASP.net中的Server.UrlEncode函数和ASP中的Server.URLEncode函数返回的值竟然不一样!!!! DIV实现下拉菜单 转 .NET 2.0 SqlDependency快速上手指南 转 SqlServer 2005 报表批量自动部署 使用XMLHTTP 获取服务器数据,实现无刷新效果 转 SQL Server 2005中设置Reporting Services发布web报表的匿名访问 - 小小小程序员 div 属性 OBJECTPROPERTY函数使用 转 数字金额大小写转换之存储过程 转 PowerDesigner教程系列 - 小小小程序员 [转载]ASP.NET 格式化字符串 转 VS.NE类、变量、文件命名规范 - 小小小程序员 转 MVC在Web系统中的模式与应用
转载 gridview在绑定显示的各种格式 - 小小小程序员 - 博客园
小小小程序员 · 2009-04-30 · via 博客园 - 小小小程序员

gridview列 数字、货币和日期 显示格式
形式 语法 结果 注释
数字 {0:N2} 12.36  
数字 {0:N0} 13  
货币 {0:c2} $12.36  
货币 {0:c4} $12.3656  
货币 "¥{0:N2}" ¥12.36  
科学计数法 {0:E3} 1.23E+001  
百分数 {0:P} 12.25% P and p present the same.
日期 {0:D} 2006年11月25日  
日期 {0:d} 2006-11-25  
日期 {0:f} 2006年11月25日 10:30  
日期 {0:F} 2006年11月25日 10:30:00  
日期 {0:s} 2006-11-26 10:30:00  
时间 {0:T} 10:30:00  

在设置gridview等数据绑定控件的模版列时,总要设置显示的格式,这里是我查询一些资料后统计出来的。
还有一个常规的选项是用数据库中默认的格式显示。

以下是一个例子
<asp:Label ID="Label2" runat="server" Text='<%# Eval("dtt","{0:d}") %>'></asp:Label>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
具体如下:
DataFormatString="{0:格式字符串}"
在GridView中如果直接设置DataFormatString为{0:d}浏览会发现并不会呈现预期的效果.
还要在HtmlEncode中把值设为False,DataGrid中不会,具体原因不清楚
在DataFormatString 中的 {0} 表示数据本身,而在冒号后面的格式字符串代表所们希望数据显示的格式;

数字、货币格式:
在指定的格式符号后可以指定小数所要显示的位数。例如原来的数据为「1.56」,若格式设定为 {0:N1},则输出为「1.5」。其常用的数值格式如下表所示:

格式字符串 输入 结果
"{0:C}" 12345.6789 $12,345.68
"{0:C}" -12345.6789 ($12,345.68)
"{0:D}" 12345 12345
"{0:D8}" 12345 00012345
"{0:E}" 12345.6789 1234568E+004
"{0:E10}" 12345.6789 1.2345678900E+004
"{0:F}" 12345.6789 12345.68
"{0:F0}" 12345.6789 12346
"{0:G}" 12345.6789 12345.6789
"{0:G7}" 123456789 1.234568E8
"{0:N}" 12345.6789 12,345.68
"{0:N4}" 123456789 123,456,789.0000
"Total: {0:C}" 12345.6789 Total: $12345.68

常用的日期时间格式:

格式 说明 输出格式
d 精简日期格式 MM/dd/yyyy
D 详细日期格式 dddd, MMMM dd, yyyy
f 完整格式 (long date + short time) dddd, MMMM dd, yyyy HH:mm
F
完整日期时间格式
(long date + long time)
dddd, MMMM dd, yyyy HH:mm:ss
g 一般格式 (short date + short time) MM/dd/yyyy HH:mm
G 一般格式 (short date + long time) MM/dd/yyyy HH:mm:ss
m,M 月日格式 MMMM dd
s 适中日期时间格式 yyyy-MM-dd HH:mm:ss
t 精简时间格式 HH:mm
T 详细时间格式 HH:mm:ss