2012-06-26 24 views
0

我目前正在與一個gridview的工作,並希望我的總分鐘字段轉換爲HH:MM轉換模板字段整數到HH:MM

這是我的代碼看起來像現在,它走的是總分鐘,回饋hh.00

</asp:TemplateField> 
       <asp:TemplateField HeaderText="Hours" HeaderStyle-Width="88px"> 
        <ItemTemplate>      
         <%# (((PendingApprovalListData)Container.DataItem).TotalMinutes/60.00).ToString("N2")%> 
        </ItemTemplate> 
+0

你是什麼這樣做會真正從TimeSpan對象中受益。你有什麼數據綁定?它是一個DataTable/DataSet,還是一個實體對象列表?我正在考慮像這個問題的公認答案:http://stackoverflow.com/questions/463642/c-what-is-the-best-way-to-convert-seconds-into-hourminutessecondsmilliseco –

回答

1
you can use this code : 

    var Hours = Math.floor(Yourvariable/60); 
    var Minutes = Yourvariable%60; 

Or you can use this 

var span = System.TimeSpan.FromMinutes(Yourvariable); 
var hours = ((int)span.TotalHours).ToString();  
var minutes = span.Minutes.ToString(); 
+0

無論如何要在客戶端做到這一點? –

+0

嘗試在您的項目模板中使用相同的語法 –

0

例 爲客戶端

<ItemTemplate> 
    <asp:Label ID="lblExemptionDate" runat="server" Text='<%#Bind("ExemptDate","{0:dd MMM yyyy HH:mm:ss}")%>'></asp:Label> 
</ItemTemplate>