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

Dynamic Report

1 Answer 205 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
thaya
Top achievements
Rank 1
thaya asked on 23 Nov 2011, 09:53 AM
I want to create a dynamic report based on any data-table.  that report provides master-detail report using subreport in report viewer using csharp.
When i create a subreport using a code behind of aspx file i could not bind a subreport.


toggle action not working in dynamic report  . 

If u have a any idea about this please share your thoughts here...


Here my code:


 DataTable data = GetData().Tables[0];
            int colsCount = data.Columns.Count;
            int RowsCount = data.Rows.Count;
            Telerik.Reporting.Drawing.Unit globalRowHeight = new Telerik.Reporting.Drawing.Unit(0.28, Telerik.Reporting.Drawing.UnitType.Inch);
            Telerik.Reporting.PageHeaderSection PageHeader = new Telerik.Reporting.PageHeaderSection();
            Telerik.Reporting.ReportHeaderSection ReportHeaderSection = new Telerik.Reporting.ReportHeaderSection();
            Telerik.Reporting.GroupHeaderSection LabelsGroupHeader = new Telerik.Reporting.GroupHeaderSection();
            Telerik.Reporting.DetailSection Detail = new Telerik.Reporting.DetailSection();
            Telerik.Reporting.GroupFooterSection labelsGroupFooter = new Telerik.Reporting.GroupFooterSection();
            Telerik.Reporting.ReportFooterSection ReportFooterSection = new Telerik.Reporting.ReportFooterSection();
            Telerik.Reporting.PageFooterSection PageFooterSection = new Telerik.Reporting.PageFooterSection();
            Telerik.Reporting.SubReport Subreport1 = new Telerik.Reporting.SubReport();

            ReportHeaderSection.Height = globalRowHeight;


            Telerik.Reporting.Panel MasterDetailPanel = new Telerik.Reporting.Panel();
            MasterDetailPanel.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.28, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch));
            MasterDetailPanel.Size = new SizeU(new Telerik.Reporting.Drawing.Unit(0.42, Telerik.Reporting.Drawing.UnitType.Cm), globalRowHeight);
            MasterDetailPanel.Style.BorderStyle.Default = BorderType.Solid;
            MasterDetailPanel.KeepTogether = true;
            MasterDetailPanel.Style.BackgroundColor = Color.CadetBlue;
            ReportHeaderSection.Style.BackgroundColor = Color.CadetBlue;

            Telerik.Reporting.Panel SubDetailPanel = new Telerik.Reporting.Panel();
            SubDetailPanel.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.28, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.4, Telerik.Reporting.Drawing.UnitType.Inch));
            SubDetailPanel.Size = new SizeU(new Telerik.Reporting.Drawing.Unit(0.42, Telerik.Reporting.Drawing.UnitType.Cm), globalRowHeight);
            SubDetailPanel.Style.BorderStyle.Default = BorderType.Solid;
            SubDetailPanel.KeepTogether = true;
            SubDetailPanel.Style.BackgroundColor = Color.BlanchedAlmond;
            for (int i = 0; i < colsCount; i++)
            {
                // ReportHeaderSection.........Start...
                Telerik.Reporting.TextBox SingleTextBox = new Telerik.Reporting.TextBox();
                SingleTextBox.Value = data.Columns[i].ColumnName.ToString();
                SingleTextBox.CanGrow = true;

                SingleTextBox.Style.BorderStyle.Default = BorderType.Solid;
                SingleTextBox.Multiline = true;
                SingleTextBox.KeepTogether = true;
                SingleTextBox.TextWrap = true;
                SingleTextBox.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Left;
                SingleTextBox.Size = new SizeU(new Telerik.Reporting.Drawing.Unit(5, Telerik.Reporting.Drawing.UnitType.Inch), globalRowHeight);
                SingleTextBox.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(i - 0.8, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(0.2, Telerik.Reporting.Drawing.UnitType.Cm));
                ReportHeaderSection.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { SingleTextBox });
                // ReportHeaderSection.........End...
                //Detail ....................Start....
                Telerik.Reporting.TextBox MasterDetailTextBox = new Telerik.Reporting.TextBox();
                MasterDetailTextBox.Value = "=Fields." + data.Columns[i].ColumnName.ToString();
                MasterDetailTextBox.CanGrow = true;
                MasterDetailTextBox.Multiline = true;
                MasterDetailTextBox.KeepTogether = true;
                MasterDetailTextBox.TextWrap = true;
                MasterDetailTextBox.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Left;
                MasterDetailTextBox.Size = new SizeU(new Telerik.Reporting.Drawing.Unit(5, Telerik.Reporting.Drawing.UnitType.Inch), globalRowHeight);
                MasterDetailTextBox.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(i - 0.6, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(0.2, Telerik.Reporting.Drawing.UnitType.Cm));


                MasterDetailPanel.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { MasterDetailTextBox });

                //  Detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { MasterDetailTextBox });
                //Detail ....................End....

            }
             ClassLibrary1.Subreport subreport = new ClassLibrary1.Subreport();
            Subreport1.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.28, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.4, Telerik.Reporting.Drawing.UnitType.Inch));
            Subreport1.Parameters.Add(new Telerik.Reporting.Parameter("Vendor_Code", null));
            Subreport1.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.7000007629394531, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(1.7000001668930054, Telerik.Reporting.Drawing.UnitType.Inch));
            //Subreport1.ReportSource.DataSource = GetData().Tables[0];
            Subreport1.ReportSource = subreport;
            Subreport1.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.28, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.5, Telerik.Reporting.Drawing.UnitType.Inch));
            Subreport1.NeedDataSource += new EventHandler(Subreport1_NeedDataSource);





            //  Detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { MasterDetailPanel });
            Detail.Height = new Telerik.Reporting.Drawing.Unit(0.42926517128944397D, Telerik.Reporting.Drawing.UnitType.Inch);
            Detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { Subreport1, MasterDetailPanel, SubDetailPanel });
            Detail.Style.BackgroundColor = Color.BurlyWood;
            //  Detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { Subreport1 });            


            Telerik.Reporting.ToggleVisibilityAction toggleVisibilityAction1 = new Telerik.Reporting.ToggleVisibilityAction();
            MasterDetailPanel.Action = toggleVisibilityAction1;
            toggleVisibilityAction1.DisplayExpandedMark = false;
            toggleVisibilityAction1.Targets.AddRange(new Telerik.Reporting.IToggleVisibilityTarget[] { SubDetailPanel });


            PageFooterSection = new Telerik.Reporting.PageFooterSection();
            PageFooterSection.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
            PageFooterSection.Style.BackgroundColor = Color.Brown;
            PageFooterSection.PrintOnFirstPage = true;
            PageFooterSection.PrintOnLastPage = true;
            Telerik.Reporting.TextBox txtFooter = new Telerik.Reporting.TextBox();
            txtFooter.Value = "='Page ' + PageNumber + ' of ' + PageCount";
            txtFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(4.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
            txtFooter.Name = "pageInfoTextBox";
            txtFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));
            //Telerik.Reporting.PictureBox picBoxFooter = new Telerik.Reporting.PictureBox();
            //picBoxFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
            //picBoxFooter.Value = @"Images\no.png";
            //picBoxFooter.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center;
            //picBoxFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(1, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))), new Telerik.Reporting.Drawing.Unit(.5D, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))));
            //picBoxFooter.Sizing = ImageSizeMode.AutoSize;
            PageFooterSection.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { txtFooter });
            Report Report = new Report();
            Report.DataSource = data;



            Report.Items.Add((ReportItemBase)PageHeader);
            Report.Items.Add((ReportItemBase)ReportHeaderSection);
            //   Report.Items.Add((ReportItemBase)LabelsGroupHeader);           
            Report.Items.Add((ReportItemBase)Detail);
            Report.Items.Add((ReportItemBase)labelsGroupFooter);
            Report.Items.Add((ReportItemBase)ReportFooterSection);
            Report.Items.Add((ReportItemBase)PageFooterSection);

            ReportViewer1.Report = Report;

        
        }
        

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 25 Nov 2011, 04:06 PM
Hello Thaya,

We will need more information in order to pinpoint what is causing the unexpected behavior. What do you mean by actions are not working? Is the toggle visibility sign missing in the MasterDetailPanel or the SubDetailPanel visibility is not altered?

About the subreport data binding. Based on the provided code snippet, you have direct access to the report definition and the datasource is not dependent on report parameter value thus you can avoid the NeedDataSource event and directly set the report definition DataSource property.

Let us know how it goes and if you still experience any difficulties we will highly appreciate if you open a support thread and send us runnable sample project to debug on our end.

Best wishes,
Peter
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
thaya
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or