David Weiser
David Weiser

Reputation: 5205

ASP.NET GridView issue with DataFormatString in a BoundField

I have a BoundField in a GridView whose datatype (in MSSQL) is time(7). The format is being displayed as:

hh:mm:ss.xxxxxx

I want to add a DataFormatString to this boundfield so that the field displays in the format:

hh:mm:ss

Here is a snippet of the .aspx file that I'm modifying:

<asp:BoundField DataField="ProcTime" HeaderText="ProcTime"

SortExpression="ProcTime" ApplyFormatInEditMode="true" HtmlEncode="true" DataFormatString="{0:F0}" />

I've tried many different format strings (t, T, d, D, m, etc) but it does not change the format of the boundfield.

What am I missing?

Upvotes: 0

Views: 2584

Answers (2)

David Weiser
David Weiser

Reputation: 5205

I figured it out (the link here gives a more in depth example).

In a nutshell, I need to add an event handler to my GridView which fires when the "OnRowDataBound" event happens. This event handler will then be in charge of changing the formatting of the text in a cell.

Upvotes: 1

Andrey
Andrey

Reputation: 1248

because you are formatting just a single value and not a set of values you do not need to specify what value to use. So the format"{0:F0}" becomes "{F0}"

Upvotes: 0

Related Questions