I have a gridview with an ObjectDataSource that comes from a linq query.
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.
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?
Thanks.
The following example demonstrates how to use the DataFormatString property to specify various formats for the columns in the DataGrid control. The Qty column is formatted as an integer, the Price column is formatted as currency, the Weight column is formatted as a decimal number, and the Expires column is formatted as a short date and time string.
Web Controls Gets or sets the string that specifies the display format for items in the column. A formatting string that specifies the display format of items in the column. The default value is Empty. The following example demonstrates how to use the DataFormatString property to specify various formats for the columns in the DataGrid control.
In versions of ASP.NET earlier than 3.5, you must set the HtmlEncode property to false in order to format fields that are not string data types. Otherwise, the field value is converted to a string by the default conversion method before the format string that is stored in the DataFormatString property is applied.
System. Web. UI. WebControls Bound Field. Data Format String Property System. Web. UI. Web Controls Gets or sets the string that specifies the display format for the value of the field. A formatting string that specifies the display format for the value of the field.
See http://msdn.microsoft.com/en-us/library/ee372287(v=vs.110).aspx Eq to use in Asp.Net MVC Metadata:
DisplayFormat(DataFormatString = "{0:hh\\:mm\\:ss}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With