Databinding RadChart to a DataView

Thread is closed for posting
3 posts, 0 answers
  1. Rick
    Rick avatar
    19 posts
    Member since:
    May 2008

    Posted 02 Jun 2008 Link to this post

    Hello,

    I'm working with a page that has a RadGrid and a RadChart that I want to tie to the same dataview so when I apply a filter to the dataview it is reflected on both the grid and the chart.

    I'm having no trouble binding the view to the grid and using the Property Builder to format it.  But when I try to basically duplicate the process with the chart I'm getting an error creating the series.

    The page load event loads the dataview like this (ignore the fact the the RadGrid references are missing, this is just a copy of the code for testing)...

    private void LoadDataView()  
        {  
            SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);  
            SqlDataAdapter da = new SqlDataAdapter();  
            DataSet ds = new DataSet();  
     
            try  
            {  
                myConn.Open();  
                da.SelectCommand = new SqlCommand("select *, DateDiff(d,TimeStamp,GetDate()) as DaysOld, DateDiff(m,TimeStamp,GetDate()) as MonthsOld,RANK() OVER (order by TIMESTAMP) as RowNumber from ReadHistory where CardID = 'ABC00002' order by TimeStamp", myConn);  
                da.Fill(ds, "ReadData");  
                DataView dv = ds.Tables["ReadData"].DefaultView;  
                Session["ReadData"] = dv;  
                RadChart2.DataSource = dv;  
                RadChart2.Series[0].DataYColumn = "Systolic";  
                RadChart2.DataBind();  
            }  
            catch (Exception ex)  
            {  
                MessageBox.Show("Error Loading Data: " + ex.Message.ToString());  
            }  
        } 

    The RadChart2.Series[0].DataYColumn = "Systolic" line is thowing the error: "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index."

    Is what I'm attempting to accomplish possible? (eg - 1 data view used by both objects?)

    Any ideas?

    Thanks in advance,
    Rick


  2. Bartholomeo Rocca
    Bartholomeo Rocca avatar
    247 posts
    Member since:
    May 2006

    Posted 03 Jun 2008 Link to this post

    Hello Rick,

    It seems the Series collection is empty and that causes the OutOfRangeException you are experiencing. Could you check whether you have a series instance in the ASPX declaration of the chart control? Alternatively, you can create one from code-behind and add it to the Series collection as well.


    Greetings,
    Bart.
  3. Rick
    Rick avatar
    19 posts
    Member since:
    May 2008

    Posted 03 Jun 2008 Link to this post

    Grrr, I'd missed the obvious....

    Thanks,
    Rick
Back to Top