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

Creating Report at runtime

3 Answers 215 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rahul Khinvasara
Top achievements
Rank 1
Rahul Khinvasara asked on 03 Feb 2009, 01:51 PM
Hi,
    I want to create a telerik report bearing the contents coming from a dataset. The report is to be created at runtime as the number of rows and columns of the dataset may vary depending on the stored procedure fired. I want to display the header on each and every page after exporting report to PDF. For displaying the header, I have created a function named "DisplayHeader()". I have currently displayed the header for the report in the detail section (and not in the header section) because the report was not displaying all the column headers on one line. I have pasted the code below :


        public Report_PDF()

        {

            /// <summary>

            /// Required for telerik Reporting designer support

            /// </summary>

            InitializeComponent();

            DBUtilReport db = new DBUtilReport(Connectionstring);

            DataSet ds = new DataSet();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.Text;

            cmd.CommandText = "select * FROM Tablename";

            db.FillDataSet(cmd, ref ds);

            

            Unit a = new Unit(100, UnitType.Pixel);

            Unit b = new Unit(100, UnitType.Pixel);

            Unit m = new Unit(10, UnitType.Pixel);

            Unit n = new Unit(40, UnitType.Pixel);

      

            int cols = ds.Tables[0].Columns.Count;      

            int paperWidth = 297;           

            int width = paperWidth / cols;

            Unit TxtBoxWidth = new Unit(width, UnitType.Pixel)+n;

            Unit k1 = new Unit(5.0, UnitType.Pixel);

            DisplayHeader(m,k1,a,ds);

            m = m + n + m;

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

            {

                Unit k = new Unit(10.0, UnitType.Pixel);

                for (int j = 0; j < ds.Tables[0].Columns.Count; j++)

                {

                    Telerik.Reporting.TextBox txtData = new Telerik.Reporting.TextBox();

                    txtData.Multiline = true;

                    txtData.TextWrap = true;

                    txtData.Style.TextAlign = HorizontalAlign.Left;

                    txtData.Style.VerticalAlign = VerticalAlign.Top;

                    txtData.Style.Font.Name = "Verdana";

                    txtData.Value = ds.Tables[0].Rows[i][j].ToString();

                    txtData.Height = new Unit(75, UnitType.Pixel);

                    txtData.Width = new Unit(100, UnitType.Pixel);

                    txtData.Left = k;

                    txtData.Top = m;

                    txtData.CanShrink = true;

                                  

                    this.detail.Items.Add(txtData);

                    k = k + a;

                }

                m = m + b;

            }

         // function for displaying the header

        protected void DisplayHeader(Unit m,Unit k1,Unit a,DataSet ds)

        {

            for (int i = 0; i < ds.Tables[0].Columns.Count; i++)

            {

                Telerik.Reporting.TextBox txtHeader = new    Telerik.Reporting.TextBox();

                txtHeader.Multiline = true;

                txtHeader.TextWrap = true;

                txtHeader.Style.TextAlign = HorizontalAlign.Left;

                txtHeader.Style.VerticalAlign = VerticalAlign.Top;

                txtHeader.Style.Font.Name = "Verdana";

                txtHeader.Style.Font.Bold = true;

                txtHeader.Value = ds.Tables[0].Columns[i].ColumnName.ToString();

                txtHeader.Height = new Unit(75, UnitType.Pixel);

                txtHeader.Width = new Unit(100, UnitType.Pixel);

                txtHeader.Left = k1;

                txtHeader.Top = m;

                txtHeader.CanShrink = true;

               

                this.detail.Items.Add(txtHeader);

                k1 = k1 + a;

            }

        }

        

3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 03 Feb 2009, 03:12 PM
Hello Rahul,

It is not clear what is your question and what are the problems you have encountered. Please elaborate on the issue, so that we can advice you accordingly.

Best wishes,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rahul Khinvasara
Top achievements
Rank 1
answered on 04 Feb 2009, 05:21 AM
Hi Steve,

              Actually we have created a report dynamically where number of columns and rows is not fixed. We have added header in detail section. But all the headers are not getting displayed on each page of the report. I have also tried to add header in header section. But when number of columns increases, then all the column headers are not displayed.

Thanks
0
Steve
Telerik team
answered on 06 Feb 2009, 12:18 PM
Hello Rahul,

Generally the groupheader section would be used to serve as headers for the columns you're going to display in the detail section. If for some reason they are not displaying, you can attach to the ItemDataBound event and debug to see what data is coming in. Most likely the problem is that they are getting overlayed on top of eachother. Please check their location and sizes - if you have a report with Width reportWidth, and you have to display columnCount columns, then each column should look like reportWidth / columnCount  wide, and the Location.X of the textboxes should be

( reportWidth / columnCount ) * 0
( reportWidth / columnCount ) * 1
( reportWidth / columnCount ) * 2
...
( reportWidth / columnCount ) * (columnCount - 1)


Please, have in mind to make the items a little bit narrower, so that they do not overlap.

Sincerely yours,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Rahul Khinvasara
Top achievements
Rank 1
Answers by
Steve
Telerik team
Rahul Khinvasara
Top achievements
Rank 1
Share this question
or