Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从 C# 更改 GridView 中列的格式
Label lblDate= (Label)(e.Row.FindControl("lblDate")); if (lblDate!= null) { lblDate.Text = (string)DataBinder.Eval(e.Row.DataItem, "event_start"); }
在<asp:BoundField>网格视图的元素上,设置DataFormatString="xxx"
<asp:BoundField>
DataFormatString="xxx"
其中“xxx”是您的格式字符串。例如DataFormatString="{0:C}",将格式化为具有默认货币符号和 2 位小数等的货币。
DataFormatString="{0:C}"
只需查看 BoundField.DataFormatString 的 MSDN 帮助以了解所有标准格式选项。