This is a migrated thread and some comments may be shown as answers.

RadDataPager always uses zero StartRowIndex

2 Answers 96 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Douglas
Top achievements
Rank 1
Douglas asked on 05 Aug 2010, 12:51 AM
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:

<%@ 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">
 
<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

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 06 Aug 2010, 01:53 PM
Hello Douglas,

I believe the problem that you are facing are due to the fact that controls collection of Chart control is created on PreRender. This prevents event bubbling of the commands from pager control buttons.

You can try implementing IPageableItemContainer and use DataPager. I believe you will expedience same behavior.

All the best,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Doug Bodden
Top achievements
Rank 1
answered on 10 Aug 2010, 12:24 AM
Thank you.

As you suggested, I did try the standard MS .Net 3.5 controls and saw the same behavior.

However, I found that by executing the SetPageProperties method in both OnLoad (with a dummy value for totalrows if !IsPostBack) and in OnPreRender (with correct values), I was able to get the pager working properly with the RadDataPager.

Thanks,
Doug
Tags
Ajax
Asked by
Douglas
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Doug Bodden
Top achievements
Rank 1
Share this question
or