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

subreport NeedDataSource not fired

0 Answers 206 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Muhammad Abrar Nazeer
Top achievements
Rank 1
Muhammad Abrar Nazeer asked on 09 Mar 2010, 11:47 AM
Respected Team,
                 I have a chart (pie) in my report which is populated by NeedDataSource event. If i set the report's data source as a datatable from webform (asp.net web page) then NeedDataSource event is fired automatically and it works fine. When I use this report as a subreport and set the datasource with same data table from Main Report then NeedDataSource is not fired and my pie chart is not displaying.
  I tried to use the RaiseNeedDataSource(chart1.GetType(), EventArgs.Empty). By this way it has been fired but in NeedDataSource event when i tried to type cast the sender (chart1) as Telerik.Reporting.Processing.Char then it returns null and eventually it failed to display the pie chart. Code is given below
1. Sub report name is rptAgedDebtor
      public rptAgedDebtor()
        {
            InitializeComponent();
            chart1.RaiseNeedDataSource(chart1.GetType(), EventArgs.Empty);
        }
2. private void chart1_NeedDataSource(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart;
            Telerik.Reporting.Chart chartDefinition = chart.ItemDefinition as Telerik.Reporting.Chart;

            ChartSeries DebtorSeries = new ChartSeries();
            DataTable tblDebtor = (System.Data.DataTable)this.DataSource;

            decimal debtorValue = 0;
            ChartSeriesItem DebtorItem = null;
            foreach (DataRow dr in tblDebtor.Rows)
            {
                debtorValue = Math.Round(Convert.ToDecimal(dr["Value"]));
                if (debtorValue == 0) continue;
                DebtorItem = new ChartSeriesItem();
                DebtorItem.Label.TextBlock.Text = string.Format("${0:##,##,##0}", debtorValue);
                DebtorItem.YValue = Convert.ToDouble(dr["Value"]);
                DebtorItem.Name = GetAgedItemTitle(dr["Name"].ToString());
                DebtorSeries.AddItem(DebtorItem);
            }
            DebtorSeries.Type = ChartSeriesType.Pie;
            DebtorSeries.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
            chartDefinition.Series.Add(DebtorSeries);
            chartDefinition.Appearance.Border.Visible = false;
            chartDefinition.ChartTitle.TextBlock.Text = "Aged Debtors";
            chartDefinition.PlotArea.Appearance.FillStyle.MainColor = System.Drawing.Color.White;
            chartDefinition.PlotArea.Appearance.FillStyle.SecondColor = System.Drawing.Color.White;
            chartDefinition.PlotArea.Appearance.Border.Visible = false;
        }

  If any one have any idea then plz give me chance of thanks.

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Muhammad Abrar Nazeer
Top achievements
Rank 1
Share this question
or