DataFormatString的使用
来源:互联网 发布:酒神淘宝店 编辑:程序博客网 时间:2024/06/05 19:23
分类:程序 |
<asp:GridView ID="grvResult" runat="server" AutoGenerateColumns="False" Width="100%">
</asp:GridView>
数据格式字符串由以冒号分隔的两部分组成,形式为 { A : Bxx }。例如,格式化字符串 {0:F2} 将显示带两位小数的定点数。
整个字符串必须放在大括号内,表示它是格式字符串,而不是实际字符串。大括号外的任何文本均显示为实际文本。
冒号前的值指定在从零开始的参数列表中的参数索引。值只能设置为 0,因为每个单元格中只有一个值。
冒号后的字符指定值的显示格式。下表列出了一些常用格式。
格式字符
C
D
E
F
G
N
X
MSDN示例:
<asp:BoundColumn HeaderText="Item" DataField="Item" ReadOnly="True" /> <asp:BoundColumn HeaderText="Quantity" DataField="Qty" DataFormatString="{0:N0}"/> <asp:BoundColumn HeaderText="Price" DataField="Price" DataFormatString="{0:c}" /> <asp:BoundColumn HeaderText="Weight" DataField="Weight" ReadOnly="True" DataFormatString="{0:F3}" /> <asp:BoundColumn HeaderText="Expires" DataField="Expires" ReadOnly="True" DataFormatString="{0:g}" />
格式日期:DataFormatString="{0: yyyy-MM-dd}"
格式时间:DataFormatString="{0: hh:mm:ss}"
说明:大写的M是 Month,小写的m是minute ,注意区别大小写,C#里其它时候了是这样的用法,要区别大小写。
格式字符串 输入 结果
"{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
- DataFormatString的使用
- DataFormatString的使用
- DataFormatString的使用
- DataFormatString的使用
- DataFormatString 的使用
- DataFormatString的使用
- GridView 中 DataFormatString 的使用
- GridView 中 DataFormatString 的使用
- GridView 中 DataFormatString 的使用
- GridView 中 DataFormatString 的使用
- DataFormatString使用笔记
- 转 GridView的DataFormatString处理格式的使用
- DataFormatString的格式化
- GridView的DataFormatString参考
- DataFormatString的格式
- GridView的dataformatstring设置
- GridView的DataFormatString
- GridView的DataFormatString属性
- SharePoint简介
- ms.net连接数据库的连接字符串
- Personbase 1.98 117版本发布了。
- 从MySpace的六次重构经历,来认识分布式系统到底该如何创建
- 类的方法名为什么叫做接口?
- DataFormatString的使用
- GetFileAttr
- SQL Server 2005 内存管理规则探秘
- 锁?不锁?如何锁?
- 提高linux经验的15个小技巧
- 二维数组的一些问题
- ListBox控件显示分类如何实现三级联动
- linux下通过脚本实现自动重启程序
- MFC数组类CArray的使用的操作详解