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


This help article describes which properties to use to bind the ASP NET AJAX Chart to a LinqDataSource and presents a code example. You can bind a RadHtmlChart to a LinqDataSource using the following properties:

  • DataSourceID in the main tag sets the declarative data source for the entire chart. You can use the DataSource property for a programmatic data source if you create the connection in the code-behind.

  • DataFieldY property (and ColorField, ExplodeField, NameField for Pie; DataFieldX for Bubble, Scatter and ScatterLine; etc.) for the series to point it to the desired data source field.

  • DataLabelsField for the x-axis labels to populate the items for the axis.

The data context, used in the following example, is created from the Northwind database:

Example 1: Bind a LinqDataSource to a RadHtmlChart.

<asp:LinqDataSource ID="LinqDataSource1" runat="server" OnSelecting="LinqDataSource1_Selecting">
<telerik:RadHtmlChart runat="server" ID="RadHtmlChart1" DataSourceID="LinqDataSource1">
            <telerik:ColumnSeries DataFieldY="UnitsInStock" Name="Units">
                <TooltipsAppearance Visible="false" />
        <XAxis DataLabelsField="ProductName">
            <LabelsAppearance />
            <MajorGridLines Visible="false" />
            <MinorGridLines Visible="false" />
            <TitleAppearance Text="Units" />
            <MinorGridLines Visible="false" />
        <Appearance Visible="false" />
    <ChartTitle Text="Units In Stock">

Example 2: Handling the Selecting event of the LinqDataSource from Example 1.

protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    LinqToSqlReadOnly.NorthwindReadOnlyDataContext northwindContext = new LinqToSqlReadOnly.NorthwindReadOnlyDataContext();
    e.Result = northwindContext.Products.Where(p => p.CategoryID == 1).Take(5);
Protected Sub LinqDataSource1_Selecting(sender As Object, e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles LinqDataSource1.Selecting
    Dim northwindContext As New LinqToSqlReadOnly.NorthwindReadOnlyDataContext()
    e.Result = northwindContext.Products.Where(Function(p) p.CategoryID = 1).Take(5)
End Sub

See Also

In this article