Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeSpan DataFormatString in Gridview

Tags:

asp.net

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.

like image 585
frenchie Avatar asked Jan 16 '11 03:01

frenchie


People also ask

How do I use the dataformatstring property in DataGrid control?

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.

What is the default value of dataformatstring?

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.

How do I format fields that are not string data types?

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.

What is the use of data format string in web system?

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.


1 Answers

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}")
like image 158
Obi Dabibobo Avatar answered Oct 12 '22 11:10

Obi Dabibobo