This is a migrated thread and some comments may be shown as answers.
DateTimeColumn TimeSpan & TimePicker
8 Answers 205 Views
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 22 Jul 2010, 01:22 PM
Hi there,

I am not able to obtain desiderd format of the TimeSpan when the grid bounds to a IList<T>. It seems there is no way to get rid of the seconds fraction of the TimeSpan, even using DataFormatString={0:t} (or  {0:HH:mm}). The column is bound to a TimeSpan property, of curse.

Furthermore, using EditMode=InPlace, the TimePiker does not pop-up nor display its list - but no error is raised either server nor client side.

I don't know what's going on, but when I set the TimePiker to limit the range of time and reduce the interval, I can no longer go to EditMode because of an error pretending the value is outside the limits. It is not so, as for the TimeSpan is passed in, however maybe that internally the TimeSpan is formatted in such a way it become no longer valid (eg: seconds wich I want to get rid of may be taken as minutes) - it is a mere speculation of curse.

Exactly how is to be managed this scenario?
Have a class with two TimeSpan (classical Start-Stop pair), have it bound to two different columns in the RadGrid, hiding the "seconds" part of the time. Let it be edited In Place with a TimePiker which range goes from 08.00 to 20.00 stepping by 30 minutes.
It shoud not be so difficult, isn't it? Evidently I do some mistake.

Thanks in advance,
Marco

8 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 28 Jul 2010, 08:05 AM
Hello Marco,

Thank you for contacting Telerik Support.

Unfortunately using the DataFormatString property would not work with TimeSpan values. The problem is that the TimeSpan object can not be formatted by the String.Format() method. Here is a small quote from one of the ASP.NET forums:

"Unfortunately, we cannot format the StartTime and EndTime columns in the same way because the TimeSpan object cannot be formatted via the BoundField's DataFormatString property. Instead we must create our own method in code that does the formatting ...".

I hope this helps

Best wishes,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Marco
Top achievements
Rank 1
answered on 26 Aug 2010, 11:24 AM
Thanks for response,

I still have to solve the second part: the edit in place.
Having the timespan as string without second causes a NullReferenceException from
Telerik.Web.UI.GridDateTimeColumnEditor.get_Text() +68
because it is no longer a standard string representation of TimeSpan, I guess.

So, how can I manage the EditInPlace getting rid of the "second" fraction of TimeSpan?
I have played around a lot prior to ask to you all, of course.

I hope you can address me or find a solution to this problem, as you may fancy at this point I'm under big pressure.

Thanks in advance for kindly response.

Marco

0
Marco
Top achievements
Rank 1
answered on 26 Aug 2010, 02:05 PM
It was my fault,

I was disturbing the databinding when the grid was in edit mode.
Now I can read, insert and edit time span without seconds.

It remain the second part: why datepicker doesn't acomplish my indication of min, max and interval? There are setted in ItemCreated as mentioned in official docs, but it takes no effect.

Kind reguards,

Marco
0
Martin
Telerik team
answered on 30 Aug 2010, 04:46 PM
Hello Marco,

Would you mind providing the code that sets the min,max and interval values of your picker?

Regards,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Felipe
Top achievements
Rank 1
answered on 22 Mar 2011, 06:11 PM
Hi,

I just wanted to say that if you target .NET 4 the Telerik controls will automatically make TimeSpan participate in composite formatting, since as of .NET 4 TimeSpan will be formatted as other types. That said, there are some idiosyncrasies in formatting TimeSpan values. The default {t} formatting will include milliseconds if they exist, so, if you want to format without the milliseconds for example, you'll have to do this:

<telerik:GridBoundColumn
    DataField="Time"
    HeaderText
="Time"
    DataType
="System.TimeSpan"
    DataFormatString
="{0:hh\:mm\:ss}">
</telerik:GridBoundColumn>

Hope this helps someone out there!
0
Martin
Telerik team
answered on 24 Mar 2011, 04:14 PM
Hello Felipe,

Thank you for making this information available for our community. It will definitely help other forum members in scenarios where TimeSpan values formatting is involved.

Kind regards,
Martin
the Telerik team
0
Marco
Top achievements
Rank 1
answered on 31 Mar 2011, 02:53 PM
Hi all,

For the last tips, it may be interesting to those who are using .Net 4.0. I strongly hope Telerik would consider the world won't migrate under .Net 4.0 just because is there: lots of efforts are waiting to be balanced befor considering that.

So we still need a solution for previous versions of the framework.

Personally I end up discarding Telerik components from that, too complicated, situation. For my own purposes it would be good to have Telerik working there, but it can be enought to have nice workig code, reglardless if it is from Telerik or not.
Basically I do use Telerik to simplify - that's why Telerik is sold.

When it happen to not simplify, well: I can code as well, perhaps some more focused, thus simpler, solution may proove the straighter way to goal.
Another tip I always recall is (KISS) to lay upon Telerik samples: when your situation is gettin too far from there, you go with it at your own risk: whether you can afford it or not is upon to you. Perhaps you can re-design the page, re-concept a process... perhaps: that is not always possible, for other "powers" rule what they shouldn't. That's where our job became hard work: but is not Telerik responsability, it is another kind of problem.
0
Brady
Top achievements
Rank 1
answered on 09 Jun 2013, 05:59 PM
A small hint or pointer to an example on how to do our own formatter would have been a lot more helpful.
Tags
Grid
Asked by
Marco
Top achievements
Rank 1
Answers by
Martin
Telerik team
Marco
Top achievements
Rank 1
Felipe
Top achievements
Rank 1
Brady
Top achievements
Rank 1
Share this question
or