I have a column generated as int from datasource, how can I change it to dispay minutes and seconds? Is there a property in Gridview?
For example. if I have value 70 to be shows as 01:10 or 1m 10s.
Edit: I did an event as suggested in comments :
protected void Grid_CustomUnboundColumnData(object sender, ASPxGridViewColumnDataEventArgs e)
{
try
{
if (e.Column.FieldName == "AdsDisplayedSeconds" || e.Column.FieldName == "UndockedSeconds")
{
TimeSpan t = TimeSpan.FromSeconds(Convert.ToInt32(e.Value.ToString()));
e.Value = string.Format("{0:D2}:{1:D2}",
t.Minutes,
t.Seconds);
}
}
catch (Exception ex)
{
LogHelper.LogError(ex);
}
}
When I am debugging, for record 70 for example, e.Value has value "01:10", but them in grid it is shown 70
3
Answers
I guess you mean TimeSpan instead DateTime.
Assumming your
int
always represents seconds:You can use converter to achive that
Than you need add resourse to Application.Resources
After all you can use it next way
Assuming a column in the GV with the int value?
Say, like this:
code to load, say this:
And we now have this:
So, we have that column with seconds – we want to convert to HH:mm:ss
We can use the row data bound event, and add this code:
And now we get: