By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,335 Members | 2,718 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,335 IT Pros & Developers. It's quick & easy.

how do I display 221 seconds as 03:41 using DataFormatString

P: n/a
Hi:

I am pulling duration out of my DB and it returns duration in seconds. For
the display i would like to show it in time format with colon

So duration of 221 I want it to display 03:41

How do I work with the DataFormatString in my bound column to do this?
Anyone know?

Thanks!

Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Stu
write your own custom function to mod on 60 for minutes and return the
rest as seconds

Nov 19 '05 #2

P: n/a
DataFormatString won't help. You should access the cell in either
ItemDataBound or PreRender event and format the value with something like
String.Format (..). You will have to convert the value to an integer, make
minutes and seconds parts and format them as separate decimals.

Eliyahu

"Tarren" <no***********@thanks.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
Hi:

I am pulling duration out of my DB and it returns duration in seconds. For the display i would like to show it in time format with colon

So duration of 221 I want it to display 03:41

How do I work with the DataFormatString in my bound column to do this?
Anyone know?

Thanks!

Nov 19 '05 #3

P: n/a
use a TimeSpan opbject and pass the '221' as the seconds parameter in the
contructor, you can then use the object to return the number of hours,
minutes, seconds, milliseconds

HTH

Ollie Riches

"Tarren" <no***********@thanks.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
Hi:

I am pulling duration out of my DB and it returns duration in seconds. For the display i would like to show it in time format with colon

So duration of 221 I want it to display 03:41

How do I work with the DataFormatString in my bound column to do this?
Anyone know?

Thanks!

Nov 19 '05 #4

P: n/a
Sorry about the messed up date - apparently it is not 1/13/2004 - I need
more sleep.

Thanks again for the help.
"Tarren" <no***********@thanks.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
Hi:

I am pulling duration out of my DB and it returns duration in seconds.
For
the display i would like to show it in time format with colon

So duration of 221 I want it to display 03:41

How do I work with the DataFormatString in my bound column to do this?
Anyone know?

Thanks!

Nov 19 '05 #5

P: n/a
Hi,

I did it using template columns. Since I bind directly to the reader and
not to a dataset, it was quicker, cleaner to do it in the aspx for my
current app than to do it in the db set.

Thanks all. Hope this helps someone else wanting to do something similar

<asp:TemplateColumn >
<ItemTemplate>
<%# Format((CLng(DataBinder.Eval(Container.DataItem, "duration")) -
(CLng(DataBinder.Eval(Container.DataItem, "duration")) Mod 60 )) / 60,"00")
%>
:
<%# Format(CLng(DataBinder.Eval(Container.DataItem, "duration")) Mod
60,"00") %>
</ItemTemplate>
</asp:TemplateColumn>

221 displays as 03:41 (i wanted the leading zero) :)

"Tarren" <no***********@thanks.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
Hi:

I am pulling duration out of my DB and it returns duration in seconds.
For
the display i would like to show it in time format with colon

So duration of 221 I want it to display 03:41

How do I work with the DataFormatString in my bound column to do this?
Anyone know?

Thanks!

Nov 19 '05 #6

P: n/a
this is a long one....you create a DateTime Instance, using the constructor
that allows you to specify seconds, and then call ToString giving it the
appropriate format string. I've not checked the syntax, but this should be
REALLY close....

<%# ctype(new
DateTime(0,0,0,0,0,ctype(dataitem,DataRowView)("du ration")),DateTime).ToStri
ng("mm:ss") %>

...note you don't have to use DataBinder.Eval when you're doing Databinding.
if you're binding to a datatable, the your DataItem is actually a
DataRowView, so you can get the value directly that way as an integer. The
DataBinder always returns Strings...therefore this would work is you wanted
to use the DataBinder Syntax...

<%# ctype(new
DateTime(0,0,0,0,0,Integer.Parse(DataBinder.Eval(C ontainer.DataItem,
"duration"))),DateTime).ToString("mm:ss") %>


"Tarren" <no***********@thanks.com> wrote in message
news:uY**************@TK2MSFTNGP10.phx.gbl...
Hi,

I did it using template columns. Since I bind directly to the reader and
not to a dataset, it was quicker, cleaner to do it in the aspx for my
current app than to do it in the db set.

Thanks all. Hope this helps someone else wanting to do something similar

<asp:TemplateColumn >
<ItemTemplate>
<%# Format((CLng(DataBinder.Eval(Container.DataItem, "duration")) -
(CLng(DataBinder.Eval(Container.DataItem, "duration")) Mod 60 )) / 60,"00") %>
:
<%# Format(CLng(DataBinder.Eval(Container.DataItem, "duration")) Mod
60,"00") %>
</ItemTemplate>
</asp:TemplateColumn>

221 displays as 03:41 (i wanted the leading zero) :)

"Tarren" <no***********@thanks.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
Hi:

I am pulling duration out of my DB and it returns duration in seconds.
For
the display i would like to show it in time format with colon

So duration of 221 I want it to display 03:41

How do I work with the DataFormatString in my bound column to do this?
Anyone know?

Thanks!


Nov 19 '05 #7

P: n/a
thanks! I'll give this one a try too. :)
"David Jessee" <dj*****@houston.rr.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
this is a long one....you create a DateTime Instance, using the
constructor
that allows you to specify seconds, and then call ToString giving it the
appropriate format string. I've not checked the syntax, but this should
be
REALLY close....

<%# ctype(new
DateTime(0,0,0,0,0,ctype(dataitem,DataRowView)("du ration")),DateTime).ToStri
ng("mm:ss") %>

..note you don't have to use DataBinder.Eval when you're doing
Databinding.
if you're binding to a datatable, the your DataItem is actually a
DataRowView, so you can get the value directly that way as an integer.
The
DataBinder always returns Strings...therefore this would work is you
wanted
to use the DataBinder Syntax...

<%# ctype(new
DateTime(0,0,0,0,0,Integer.Parse(DataBinder.Eval(C ontainer.DataItem,
"duration"))),DateTime).ToString("mm:ss") %>


"Tarren" <no***********@thanks.com> wrote in message
news:uY**************@TK2MSFTNGP10.phx.gbl...
Hi,

I did it using template columns. Since I bind directly to the reader and
not to a dataset, it was quicker, cleaner to do it in the aspx for my
current app than to do it in the db set.

Thanks all. Hope this helps someone else wanting to do something similar

<asp:TemplateColumn >
<ItemTemplate>
<%# Format((CLng(DataBinder.Eval(Container.DataItem, "duration")) -
(CLng(DataBinder.Eval(Container.DataItem, "duration")) Mod 60 )) /

60,"00")
%>
:
<%# Format(CLng(DataBinder.Eval(Container.DataItem, "duration")) Mod
60,"00") %>
</ItemTemplate>
</asp:TemplateColumn>

221 displays as 03:41 (i wanted the leading zero) :)

"Tarren" <no***********@thanks.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
> Hi:
>
> I am pulling duration out of my DB and it returns duration in seconds.
> For
> the display i would like to show it in time format with colon
>
> So duration of 221 I want it to display 03:41
>
> How do I work with the DataFormatString in my bound column to do this?
> Anyone know?
>
> Thanks!
>
>
>



Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.