2016-11-10 42 views
0

我試圖通過僅顯示HH:mm來重新格式化GridView中顯示的時間。當然,我的時間顯示爲HH:mm:ss。編碼如下。DataFormatString for time(ASP.Net)

<asp:BoundField HeaderStyle-CssClass="thStyle" DataField="time" HeaderText="Time Upload" /> 

我試圖DataFormatString="{0:HH:mm}"但是當我運行系統丟給我一個錯誤是

輸入字符串的不正確的格式。

謝謝。

+1

看在[這個StackOverflow的問題]的答案(http://stackoverflow.com/questions/4703695/timespan-dataformatstring-in-gridview)。 –

+0

@ ChrisR.Timmons感謝您的有用信息。我試着用'DataFormatString =「{0:t}」'來解決這個問題,並返回給我'HH:mm:ss'。如果我使用'YourGridView_RowDataBound',它會給我錯誤**從類型'TimeSpan'到類型'Boolean'的轉換在行上無效** If e.Row.DataItem(「YourColName」)Then' – Emerald

回答

1

管理得到HH:mm使用HtmlEncode="false" DataFormatString="{0:hh\:mm}"