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

GridCalculatedColumn Concatination with formatting

6 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
DoomerDGR8 asked on 25 Oct 2010, 10:49 AM
Hello!

I'm trying to use GridCalculatedColumn in order to show concatenated and formatted values.

I need to show StartTime and EndTime as 08:45 AM - 01:45 PM
Similarly, Rate and RatePlus as £15.50 + £14.00

Successfully doing this will help me eliminate two/four columns. However, formatting is utmost necessary. My web applications culture is set to UK in web.config. The data source being fed to the grid is coming through LINQ -> DataTable -> Grid. Commenting these two GridCalculatedColumn makes everything run just fine. However, with these two columns, I get the following error upon Databind():
Expression of type 'System.Nullable`1[System.DateTime]'
cannot be used for parameter of type 'System.Object'
of method 'System.String Concat(System.Object, System.Object)'

I have confirmed that no null value is present in the result of the query.

<telerik:GridCalculatedColumn
    UniqueName
="Timings"
    HeaderText
="Timings"
    DataType
="System.DateTime"
    DataFields="StartTime, EndTime"
    Expression
='{0} + "&nbsp;" + "-" + ";&nbsp;" + {1}'
    DataFormatString="{0:hh:mm tt}" />

<telerik:GridCalculatedColumn
    UniqueName
="Rates"
    HeaderText
="Rates"
    DataType
="System.Decimal"
    DataFields="Rate, RatePlus"
    Expression
='{0} + "&nbsp;" + "+" + ";&nbsp;" + {1}'
    DataFormatString="{0:C2}" />

Any help will be highly appreciated.

Regards.

6 Answers, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 28 Oct 2010, 11:42 AM
Hello Hassan,

In order to achieve your goal, I would sugget that you use GridTemplateColumn and define its ItemTemplate as below:

<telerik:GridTemplateColumn>
    <ItemTemplate>
        <%# string.Format("{0:hh:mm tt} - {1:hh:mm tt}", Eval("StartTime"), Eval("EndTime")) %>
    </ItemTemplate>
</telerik:GridTemplateColumn>


Sincerely yours,
Iana
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
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 28 Oct 2010, 11:51 AM
Beautiful and simple!

<telerik:GridTemplateColumn UniqueName="Timings" HeaderText="Timings">
    <ItemTemplate>
        <%# string.Format("{0:hh:mm tt} - {1:hh:mm tt}", Eval("StartTime"), Eval("EndTime")) %>
    </ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="Rates" HeaderText="Rates">
    <ItemTemplate>
        <%# string.Format("{0:c2} + {1:c2}", Eval("Rate"), Eval("RatePlus"))%>
    </ItemTemplate>
</telerik:GridTemplateColumn>

Thanks a bunch, Lana!
0
Pooya
Top achievements
Rank 1
answered on 21 Sep 2011, 12:00 PM
I have a rather similar issue but the difference is that all the columns are generated in code.

How to create the GridTemplateColumn in code?

Thanks
0
Iana Tsolova
Telerik team
answered on 21 Sep 2011, 02:27 PM
Hello Pooya,

Check out this help topic for more information on RadGrid programmatic creation.

Best wishes,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Anil
Top achievements
Rank 1
answered on 10 Jan 2012, 12:14 PM
How to merge two column heading in RadGrid in Telerik Control
0
Shinu
Top achievements
Rank 1
answered on 10 Jan 2012, 01:00 PM
Hello Anil,

Check the following help documentation which explains more about this
Customizing with GridTemplateColumn

-Shinu.
Tags
Grid
Asked by
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Iana Tsolova
Telerik team
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
Pooya
Top achievements
Rank 1
Anil
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or