Creating Report at runtime

4 posts, 0 answers
  1. Rahul Khinvasara
    Rahul Khinvasara avatar
    303 posts
    Member since:
    Aug 2007

    Posted 03 Feb 2009 Link to this post

    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;

                }

            }

     

     

            
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 03 Feb 2009 Link to this post

    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.
  3. Rahul Khinvasara
    Rahul Khinvasara avatar
    303 posts
    Member since:
    Aug 2007

    Posted 03 Feb 2009 Link to this post

    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
  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 06 Feb 2009 Link to this post

    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.
Back to Top