TimeSpan DataFormatString in Gridview

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

One of the source variables is a period of time, and I bind the associated field with DataField = "MyTimeSpanVariable". Data contains time in seconds and minutes and very rarely in hours.

The data is displayed in its own format, but when I add HtmlEncode = "false" DataFormatString = "{0: hh: mm: ss}" to the properties of the linked field on the aspx page, it drops on the MyGridView.Databind () line. What am I doing wrong?

Thank.

+5
source share
5 answers

If you like, you can try formatting your field in the Grid RowDataBound event.

For instance:

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
-1

, ":", #. :

DataFormatString=@"Time is {0:H\:mm}";
+4

!:
FormatException on DataFormatString="Mødetidspunkt er {0:H:mm}"

, .

DataFormatString="Time is {0:t}"
t is the equivalent of HH:mm
T is the equivalent of HH:mm:ss

. " DateTime" .

+3

aspx/ascx -

HtmlEncode="false" DataFormatString="{0:mm\:ss}" 
+3

. http://msdn.microsoft.com/en-us/library/ee372287(v=vs.110).aspx Eq Asp.Net MVC:

DisplayFormat(DataFormatString = "{0:hh\\:mm\\:ss}")
+2

All Articles