I am trying to implement pageable charts by implementing the IRadPageableItemContainer in a class extending MS' System.Web.DataVisualization chart components.
When I add a RadDataPager to the page, and associate it with the chart control, the RadDataPager always sets the StartRowIndex (in SetPageProperties) to zero. It never advances the position (with any of the buttons or fields), or allows me to select a different number of results per page.
Using Win XP SP3, FireFox 3.6 and IE 7/8, VS2008/.Net 3.5, with the RadControls for ASP.NET Ajax Q1 2010.
Here's my markup:
Here's my code-behind:
And here's the extended chart class (though the problem does not seem to be related to this class):
Thanks,
Doug
When I add a RadDataPager to the page, and associate it with the chart control, the RadDataPager always sets the StartRowIndex (in SetPageProperties) to zero. It never advances the position (with any of the buttons or fields), or allows me to select a different number of results per page.
Using Win XP SP3, FireFox 3.6 and IE 7/8, VS2008/.Net 3.5, with the RadControls for ASP.NET Ajax Q1 2010.
Here's my markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DougRadDataPagerTest1.aspx.cs" Inherits="KMI.IntelliDrive.Appl.Web.UI.test.DougRadDataPagerTest1" %><%@ Register Assembly="IntelliDriveChartControls" Namespace="IntelliDrive.Charting" TagPrefix="cc1" %><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <telerik:RadScriptManager runat="server"></telerik:RadScriptManager> <asp:Button ID="Button1" runat="server" Text="Clear Data" onclick="Button1_Click" /> <div> <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" EnableAJAX="true" > <cc1:PageableChart ID="newChart" runat="server" ImageStorageMode="UseHttpHandler" PagingEnabled="true" EnableViewState="True"> <Titles> <asp:Title Text="Title"></asp:Title> </Titles> <ChartAreas> <asp:ChartArea Name="ChartArea1"> <AxisY > <LabelStyle Format="{$#,##0;($#,##0)}" /> </AxisY> </asp:ChartArea> </ChartAreas> </cc1:PageableChart> <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="newChart" Enabled="true" BorderStyle="Ridge" Visible="true"> <Fields> <telerik:RadDataPagerButtonField FieldType="FirstPrev" /> <telerik:RadDataPagerButtonField FieldType="Numeric" /> <telerik:RadDataPagerButtonField FieldType="NextLast" /> <telerik:RadDataPagerPageSizeField PageSizeText="Page size: " /> <telerik:RadDataPagerGoToPageField CurrentPageText="Page: " TotalPageText="of" SubmitButtonText="Go" TextBoxWidth="15" /> <telerik:RadDataPagerTemplatePageField> <PagerTemplate> <div > <b>Items <asp:Label runat="server" ID="Label1" Text="<%# Container.Owner.StartRowIndex+1%>" /> to <asp:Label runat="server" ID="Label2" Text="<%# Container.Owner.StartRowIndex+Container.Owner.PageSize %>" /> of <asp:Label runat="server" ID="Label3" Text="<%# Container.Owner.TotalRowCount%>" /> <br /> </b> </div> </PagerTemplate> </telerik:RadDataPagerTemplatePageField> </Fields> </telerik:RadDataPager> </telerik:RadAjaxPanel> </div> </form></body></html>Here's my code-behind:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.DataVisualization.Charting;using Telerik.Web.UI;namespace KMI.IntelliDrive.Appl.Web.UI.test{ public partial class DougRadDataPagerTest1 : System.Web.UI.Page { //protected void Page_Load(object sender, EventArgs e) //{ //} protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (Session["DUMMYDATA"] == null) { Dictionary<String, Int32> dummy = new Dictionary<string, int>(); dummy.Add("one", 1); dummy.Add("two", 2); dummy.Add("three", 3); dummy.Add("seven", 7); dummy.Add("fortytwo", 42); dummy.Add("five", 5); dummy.Add("elevensies", 11); dummy.Add("mastodon", 10); dummy.Add("rock", 2); dummy.Add("splunge", 14); dummy.Add("parrot", 15); dummy.Add("defenestrate", 16); dummy.Add("cat", 17); dummy.Add("window", 18); Session["DUMMYDATA"] = dummy; } SetCommonControls(); newChart.DataSource = Session["DUMMYDATA"] as Dictionary<String, Int32>; newChart.DataBind(); } private void SetCommonControls() { string myEntityTitle = "Doug Test"; newChart.Series.Clear(); Series ser = new Series(myEntityTitle + " Change in Dollars"); ser.Name = myEntityTitle; ser.ChartType = SeriesChartType.Bar; ser.XValueMember = "key"; ser.YValueMembers = "value"; // Add the series to the chart. newChart.Series.Add(ser); // DCB FIXME trying paging //_chart.PagingEnabled = true; newChart.Titles[0].Text = myEntityTitle; //Set up click event properties //newChart.Series[0].PostBackValue = "#SERIESNAME;#AXISLABEL;#VALY;#INDEX"; } protected void Button1_Click(object sender, EventArgs e) { Session.Remove("DUMMYDATA"); } }}And here's the extended chart class (though the problem does not seem to be related to this class):
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI.DataVisualization.Charting;using Telerik.Web.UI;using System.Collections;namespace IntelliDrive.Charting{ public class PageableChart : Chart, IRadPageableItemContainer { public Boolean PagingEnabled; private Dictionary<String, Int32> _pagedDataSource; public override void DataBind() { int startRowIndex = ViewState["_startRowIndex"] != null ? (int)ViewState["_startRowIndex"] : 0; int rowsPerPage = ViewState["_rowsPerPage"] != null ? (int)ViewState["_rowsPerPage"] : 10; //// intercept the original data source, and databind to the proper range //// by interpreting the paging information if paging is enabled. int totalRows = 0; if (PagingEnabled) { // calculate the range based on paging member variables. if ((DataSource as Dictionary<String, Int32>) != null) { Dictionary<String,Int32> ds = DataSource as Dictionary<String,Int32>; // This section pulls the selected "page" of data out of the full datasource. totalRows = ds.Count; int rowIndex = 0; _pagedDataSource = new Dictionary<string,int>(); foreach (String s in ds.Keys) { if (rowIndex >= startRowIndex && rowIndex < startRowIndex + rowsPerPage) { _pagedDataSource[s] = ds[s]; } rowIndex++; } this.DataSource = _pagedDataSource; } else { throw new ApplicationException("DCB FIXME - Can't cast the DataSource to Dictionary<String,Int32>, or DataSource isn't set by DataBind()."); } } base.DataBind(); // fire this event AFTER the databind? FIXME could this be placed up in the prior PagingEnabled block for cleanness? if (PagingEnabled) { OnTotalRowCountAvailable(new RadDataPagerPageEventArgs(startRowIndex, rowsPerPage, totalRows)); } } #region IRadPageableItemContainer Members public int MaximumRows { get { return ViewState["_rowsPerPage"] != null ? (int)ViewState["_rowsPerPage"] : 7; } } // Why does "startRowIndex" always show up as 0? The pager never changes it... public void SetPageProperties(int startRowIndex, int maximumRows, bool databind) { this.ViewState["_startRowIndex"] = startRowIndex; this.ViewState["_rowsPerPage"] = maximumRows; // it's got to re-bind since we bind manually to the paged data. RequiresDataBinding = true; } public int StartRowIndex { get { return (ViewState["_startRowIndex"] != null ? (int)ViewState["_startRowIndex"] : 0); } } public event EventHandler<RadDataPagerPageEventArgs> TotalRowCountAvailable; #endregion protected virtual void OnTotalRowCountAvailable(RadDataPagerPageEventArgs e) { if (TotalRowCountAvailable != null) TotalRowCountAvailable(this, e); } }}Thanks,
Doug