Aggregate numeric values for nvarchar column

3 posts, 0 answers
  1. Clive Hoggar
    Clive Hoggar avatar
    349 posts
    Member since:
    Nov 2008

    Posted 30 May 2016 Link to this post


    Please help me out!

    I have recently purchased a licence for the Q2 2016 devcraft tools and I am working on a website update...

    I have a database in which numeric values have been recorded historically in an nvarchar column. I can't readily change the column type as it is in production and has several years of data in it.

    However I would now like to use the aggregate function to put sum totals in a footer.  How can I achieve this from where we are now - i.e. with a non-numeric data column? Obviously I get an error just adding aggregate="Sum" ( 'Sum is not supported for type system.object').

    I tried cheating by just changing the column from gridbound to gridnumeric but it is not so easily fooled!

    Can you suggest what is the best way to get from the nvarchar database column I have now,  to getting an aggregate sum in the footer?



    Using Q2 2016 controls in VS 2015


  2. Clive Hoggar
    Clive Hoggar avatar
    349 posts
    Member since:
    Nov 2008

    Posted 31 May 2016 in reply to Clive Hoggar Link to this post

    Just to add....

    I have tried creating a new numeric column and then processing the nvarchar item in itemdatabound event to populate the new column with decimal values. That works up to the point I tried to add Aggregate=sum to the numeric field I created.

    Runtime Error then is "[column]  is neither a DataColumn nor a DataRelation for table"

    Still stumped...



  3. Viktor Tachev
    Viktor Tachev avatar
    2501 posts

    Posted 31 May 2016 Link to this post

    Hello Clive,

    The GridNumericColumn expects that the underlying data will be a numeric value. This is why it is expected to see an error when the field in the database keeps the data as string.

    You said that updating the field in the database to numeric is not an option. In that case you would need to implement the logic for the aggregates manually. You can set the AggregateFunction for the column to Custom. With that setup the CustomAggregate event will be raised by the grid. In the handler you can add the custom logic that will be used to calculate the aggregate.

    Viktor Tachev
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top