GridCalculatedColumn - Nothing But Zeros

4 posts, 0 answers
  1. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 25 Aug 2011 Link to this post

    Hi

    If I have the following SQL:

    SELECT CAST
    (
        (
            CAST(10549 AS FLOAT) / CAST(93020 AS FLOAT) * 100
        )
        AS DECIMAL (10,2)
    )
    AS BobsPerAlice

    I can expect the following output:

    BobsPerAlice
    11.34

    I'd like to replicate this in a GridCalculatedColumn and this is what I came up with:

    <telerik:GridCalculatedColumn
        DataType="System.Double"
        HeaderText="Bobs"
        UniqueName="Bobs"
        DataFields="Bobs, Alice"
        Expression="{0} / {1} * 100"
        FooterText="Bobs / Alice: "
        Aggregate="Sum">
    </telerik:GridCalculatedColumn>

    Unfortunately, the rows I get contain zeros for their values as does the footer item, like:

    Bobs
    0
    0
    0
    ...
    Bobs / Alice: 0

    "Bob" and "Alice" are of database type INT. Working with INTs will not work though.

    What am I doing wrong?

    Richard
  2. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 31 Aug 2011 Link to this post

    Hello Richard,

    I tried to reproduce the described issue but to no avail. I am sending you a simple example based on your code, please check it out and let me know what differs in your case.

    Looking forward for your reply.

    Regards,
    Radoslav
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 31 Aug 2011 Link to this post

    I think it's to do with the Expression. If the expression evaluates to something the GridCalculatedColumn doesn't like, it doesn't show anything.

    As a more concrete example, I'm trying to take 2 columns that have a datatype of int (Litres of Fuel placed in fuel tank and Odometer reading at the time of fill-up) and show the Litres / 100Km as a footer item while still showing the individual Litres of Fuel in that column.

    <telerik:GridNumericColumn 
        DataField="Odometer" 
        DataType="System.Int32" 
        HeaderText="Odometer" 
        UniqueName="Odometer">
    </telerik:GridNumericColumn>
      
    <telerik:GridCalculatedColumn 
        DataType="System.Int32"
        HeaderText="Litres" 
        UniqueName="Litres" 
        DataFields="Litres,Odometer" 
        Expression="({0} X 100) / {1}" 
        FooterText="L / 100 Km: "
        Aggregate="Sum">
    </telerik:GridCalculatedColumn>

    Does not work.

    Richard
  5. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 03 Sep 2011 Link to this post

    Hi Richard,

    Could you please try changing the Expression of the GridCalculatedColumn as following and let me know if the issue still persists:
    <telerik:GridCalculatedColumn DataType="System.Int32" HeaderText="Litres" UniqueName="Litres"
                        DataFields="Litres,Odometer" Expression="({0} * 100) / {1}" FooterText="L / 100 Km: "
                        Aggregate="Sum">
                    </telerik:GridCalculatedColumn>

    Additionally I am sending you the modified version of the example.

    Looking forward for your reply.

    Regards,
    Radoslav
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top