Gridview中的TimeSpan DataFormatString [英] TimeSpan DataFormatString in Gridview

查看:49
本文介绍了Gridview中的TimeSpan DataFormatString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有来自linq查询的ObjectDataSource的gridview.

I have a gridview with an ObjectDataSource that comes from a linq query.

来源的变量之一是时间跨度,我将绑定域与DataField ="MyTimeSpanVariable"绑定.数据包含以秒和分钟为单位的时间,很少以小时为单位.

One of the variables of the source is a timespan and I'm binding a boundfield with the DataField="MyTimeSpanVariable". The data contains times in seconds and minutes and very rarely in hours.

数据以其原始格式显示正常,但是当我将HtmlEncode ="false" DataFormatString ="{0:hh:mm:ss}"添加到aspx页面的boundfield属性中时,它在MyGridView.Databind() 线.我在做什么错了?

The data displays fine in its native format but when I add HtmlEncode="false" DataFormatString="{0:hh:mm:ss}" to the boundfield properties in the aspx page, it crashes on the MyGridView.Databind() line. What am I doing wrong?

谢谢.

推荐答案

如果愿意,可以尝试在Grid的RowDataBound事件上格式化字段.

If you like, you can try formatting your field on the Grid's RowDataBound event.

例如:

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

这篇关于Gridview中的TimeSpan DataFormatString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆