Format Gridview Time

Asked

Viewed 375 times

0

Good morning, I have a field on the grid, which is filled from SQL a Time field(7).

It appears this way in the grid: 15:10:51.1000000

But I would like it to appear like this: 15:10:51, and in every way I try, not really, I tried like this: Dataformatstring="{0:hh: mm}", like : Dataformatstring="{0:t}"

Either it gives error in the string or it simply doesn’t convert to the right format. I would like to know the right way to convert in the column on the grid. Thank you.

No way I try to work out, has any way to set the Gridview time ??

  • 1

    I don’t know if it would work for you, but I use hour.Tostring("HH:mm:ss"). But I don’t think that’s your case.

  • Because it’s William it’s because I set up right inside the Gridview. Thank you.

1 answer

2

Use it like this:

DataFormatString="{0:HH:mm}"

The HH has to be capitalized

Example:

<asp:BoundField DataField="hora" HeaderText="Hora" SortExpression="Hora" DataFormatString="{0:HH:mm}" ShowHeader="True" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"/>
  • Tentei dessa forma Tiago, porém não funciona, estou configurando direto dentro do GridView. "<asp:BoundField DataField="hora" HeaderText="Hora" SortExpression="Hora" DataFormatString="HH:mm" ShowHeader="True" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"/>"

  • @marianac_costa see this suits you

  • James tried it exactly this way, and it returns me the following error: "Exception Details: System.Formatexception: Input string was not in an incorrect format." I’ve tried with seconds too, returns me the same error, when I take the Dataformatstring it works normal.

  • Try this format {0:HH/mm}

  • Same error James. I can’t format the time inside Gridview

Browser other questions tagged

You are not signed in. Login or sign up in order to post.