GridCalculatedColumn Concatination with formatting

7 posts, 1 answers
  1. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 25 Oct 2010 Link to this post

    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.
  2. Answer
    Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 28 Oct 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 28 Oct 2010 Link to this post

    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!
  5. Pooya
    Pooya avatar
    107 posts
    Member since:
    Apr 2011

    Posted 21 Sep 2011 Link to this post

    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
  6. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 21 Sep 2011 Link to this post

    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
  7. Anil
    Anil avatar
    1 posts
    Member since:
    Jan 2012

    Posted 10 Jan 2012 Link to this post

    How to merge two column heading in RadGrid in Telerik Control
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Jan 2012 Link to this post

    Hello Anil,

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

    -Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017