New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Creating an Object that can be Consumed by ObjectDataSource

RadChart has been replaced by RadHtmlChart, Telerik's client-side charting component. If you are considering RadChart for new development, examine the RadHtmlChart documentation and online demos first to see if it will fit your development needs. If you are already using RadChart in your projects, you can migrate to RadHtmlChart by following these articles: Migrating Series, Migrating Axes, Migrating Date Axes, Migrating Databinding, Features parity. Support for RadChart is discontinued as of Q3 2014, but the control will remain in the assembly so it can still be used. We encourage you to use RadHtmlChart for new development.

See the code below for an example object that can be consumed by ObjectDataSource. Your object needs to be marked with the DataObjectAttribute for the object to be seen by Data Source Configuration Wizard. It also needs a method to select data marked by the DataObjectMethodAttribute (see GetProducts() method in the code sample).

See Data Binding RadChart to an ObjectDataSource for an example of how to use this object for binding.

using System;
using System.Configuration;
using System.Web.UI.WebControls;
// Supports RadChart declaration
using Telerik.Web.UI;
// Supports RadChart objects, i.e. series, items
using Telerik.Charting;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Collections;
namespace RadChartBinding
{
    [DataObjectAttribute()]
    public class ProductsBO
    {
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public static IEnumerable GetProducts()
        {
            SqlCommand command = new SqlCommand();
            command.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
            command.CommandText = "SELECT CategoryName, SUM(ProductSales) AS TotalSales FROM [Product Sales for 1997] GROUP BY CategoryName";
            command.Connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            return reader;
        }
    }
}
Imports System
Imports System.Configuration
Imports System.Web.UI.WebControls
' Supports RadChart declaration
Imports Telerik.Web.UI
' Supports RadChart objects, i.e. series, items
Imports Telerik.Charting
Imports System.Data.SqlClient
Imports System.ComponentModel

Namespace RadChartBinding
    <DataObjectAttribute()> _
    Public Class ProductsBO
<DataObjectMethodAttribute(DataObjectMethodType.[Select], True)>_  
        Public Shared Function GetProducts() As IEnumerable
            Dim command As New SqlCommand()
            command.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)
            command.CommandText = "SELECT CategoryName, SUM(ProductSales) AS TotalSales FROM [Product Sales for 1997] GROUP BY CategoryName"
            command.Connection.Open()
            Dim reader As SqlDataReader = command.ExecuteReader()
            Return reader
        End Function
    End Class
End Namespace

See Also

In this article