This is a migrated thread and some comments may be shown as answers.

GridCalculatedColumn and DataFormatString

3 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrea Gorin
Top achievements
Rank 2
Andrea Gorin asked on 30 Dec 2009, 01:31 PM
I have a GridCalculatedColumn with a datetime expression (returns a timespan), the option DataFormatString don't work!

Why?

                                <telerik:GridCalculatedColumn DataFields="DataOraFineSessione,DataOraInizioSessione" Expression="{0}-{1}"
                                    HeaderText="Durata" UniqueName="Durata" DataType="System.TimeSpan"
                                    DataFormatString="{0:T}">
                                </telerik:GridCalculatedColumn>

I work with the last versione of telerik controls for asp.net 3.5.

Andrea

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Dec 2009, 02:48 PM
Hello Andrea,

As far as I know DataFormatString won't work for TimeSpan objects. Please examine the following link:
Standard Date and Time Format Strings

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Andrea Gorin
Top achievements
Rank 2
answered on 30 Dec 2009, 04:32 PM
Ok,

Any simple solution to suggest for the question: the differenze for two date ?

Thanks, Andrea  
0
Daniel
Telerik team
answered on 04 Jan 2010, 05:07 PM
Hello Andrea,

For your convenience I created a runnable demo (attached to this post) that shows how can format the TimeSpan manually.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        TimeSpan myTS = TimeSpan.Parse(item["Durata"].Text);
        item["Durata"].Text = String.Format("{0}h {1}m {2}s", myTS.Days, myTS.Hours, myTS.Minutes);
    }
}

<telerik:GridCalculatedColumn DataFields="DataOraFineSessione,DataOraInizioSessione"
    Expression="{0}-{1}" HeaderText="Durata" UniqueName="Durata" DataType="System.TimeSpan">
</telerik:GridCalculatedColumn>

I hope this helps.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Andrea Gorin
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Andrea Gorin
Top achievements
Rank 2
Share this question
or