C# Gridview 字段格式

GridView 显示数据时常常会有多种字段格式,比如:时间、数字、货币、身份证号等,尤其是身份证号的显示常常会显示成科学计数法,

要解决其实很容易,给每个字段设置类型就可以了:

 

常用格式:

 

1) 文本:vnd.ms-excel.numberformat:@
2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
3) 数字:vnd.ms-excel.numberformat:#,##0.00
4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
5) 百分比:vnd.ms-excel.numberformat: #0.00%

 

使用方法:

gridview 的 RowDataBound 事件中添加

 

//其中i表示列数,从0开始

e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@;");

 

发布了86 篇原创文章 · 获赞 19 · 访问量 56万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章