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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章