Asp.net Gridview中的TimeSpan DataFormatString
我有一个gridview,其中包含一个来自linq查询的ObjectDataSource 源的一个变量是timespan,我正在将一个boundfield与DataField=“MyTimeSpanVariable”绑定。数据包含以秒和分钟为单位的时间,很少以小时为单位 数据以其本机格式显示良好,但当我将HtmlEncode=“false”DataFormatString=“{0:hh:mm:ss}”添加到aspx页面的boundfield属性时,它在MyGridView.Databind()行上崩溃。我做错了什么Asp.net Gridview中的TimeSpan DataFormatString,asp.net,Asp.net,我有一个gridview,其中包含一个来自linq查询的ObjectDataSource 源的一个变量是timespan,我正在将一个boundfield与DataField=“MyTimeSpanVariable”绑定。数据包含以秒和分钟为单位的时间,很少以小时为单位 数据以其本机格式显示良好,但当我将HtmlEncode=“false”DataFormatString=“{0:hh:mm:ss}”添加到aspx页面的boundfield属性时,它在MyGridView.Databind()行
谢谢。如果您愿意,可以尝试在网格的RowDataBound事件中格式化字段 例如:
Protected Sub YourGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles YourGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DataItem("YourColName") Then
'Do formatting
End If
End If
End Sub
DataFormatString=@"Time is {0:H\:mm}";
我也有同样的问题!:
DataFormatString=“Mødetidspunkt er{0:H:mm}”上的FormatException 不能使用两个冒号,因此请使用短时格式说明符
DataFormatString="Time is {0:t}"
t等于HH:mm
T相当于HH:mm:ss
请参阅。我认为如果使用C#,您需要避开第二个“:”。例如:
Protected Sub YourGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles YourGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DataItem("YourColName") Then
'Do formatting
End If
End If
End Sub
DataFormatString=@"Time is {0:H\:mm}";
从aspx/ascx来看,这可能是
HtmlEncode="false" DataFormatString="{0:mm\:ss}"
看
Asp.Net MVC元数据中要使用的Eq:
DisplayFormat(DataFormatString = "{0:hh\\:mm\\:ss}")