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

Dynamic crosstab report

3 Answers 298 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
sebastian
Top achievements
Rank 1
sebastian asked on 12 Jul 2012, 08:44 AM
Hi,

I need to know how can I prepare dynamic crosstab report. I used code from examples. But it's generate only header row and one data row.

private void crosstab1_ItemDataBinding(object sender, EventArgs e)
        {
           //Connections and commands
           .....
 
            //get the processing table object since we're in the context of event
            Telerik.Reporting.Processing.Table processingTable = (sender as Telerik.Reporting.Processing.Table);
            //construct the select statement based on the selected report parameters
            
            SqlDataAdapter sqlAdapter = new SqlDataAdapter(sComm);
            sqlAdapter.SelectCommand.CommandTimeout = 3600;
            //create a dataset, fill it and set it as datasource to the processing table object
            DataSet ds = new DataSet();
            sqlAdapter.Fill(ds);
            processingTable.DataSource = ds.Tables[0];
 
            //create two HtmlTextBox items (one for header and one for data) which would be added to the items collection of the table
            Telerik.Reporting.HtmlTextBox textboxGroup;
            Telerik.Reporting.HtmlTextBox textBoxTable;
 
            //we do not clear the Rows collection, since we have a details row group and need to create columns only
            this.crosstab1.ColumnGroups.Clear();
            this.crosstab1.Body.Columns.Clear();
            this.crosstab1.Body.Rows.Clear();
            int i = 0;
            this.crosstab1.ColumnHeadersPrintOnEveryPage = true;
            DataTable dt = ds.Tables[0];
 
            foreach (DataColumn dc in dt.Columns)
            {
                Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
                this.crosstab1.ColumnGroups.Add(tableGroupColumn);
                this.crosstab1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Inch(1)));
 
                textboxGroup = new Telerik.Reporting.HtmlTextBox();
                textboxGroup.Style.BorderColor.Default = Color.Black;
                textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
                textboxGroup.Value = dc.ColumnName;
                textboxGroup.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
                tableGroupColumn.ReportItem = textboxGroup;
 
                textBoxTable = new Telerik.Reporting.HtmlTextBox();
                textBoxTable.Style.BorderColor.Default = Color.Black;
                textBoxTable.Style.BorderStyle.Default = BorderType.Solid;
                textBoxTable.Value = "=Fields." + dc.ColumnName;
                textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
                this.crosstab1.Body.SetCellContent(0, i++, textBoxTable);
                this.crosstab1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
            }
        }

3 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 12 Jul 2012, 02:35 PM
If it is a crosstab you need:
  1. Body Rows
  2. Body Columns
  3. Row Groups
  4. Column Groups
  5. You need to set the content for every single cell that is formed
  6. If the groups have headers, there will be more cells to fill up and it very hard to predict it.
The best thing to do is to create at design-time a couple of crosstabs and see the auto-generated code. If you catch the pattern you might be able to build a dynamic one. 

0
Jorge
Top achievements
Rank 1
answered on 09 Jul 2013, 08:51 PM
Hi,

I have the same problem.

I managed to insert the headers, but the other rows are repeated with the data from the first column.

Programmatically, I managed to get only one row correctly, but others do not

Have you a simple example of how to fill the data in the cells or use RowGroups?
0
Stef
Telerik team
answered on 11 Jul 2013, 06:26 PM
Hello Jorge,

Basically you need to create the Crosstab item definition, then just set its DataSource property. Our suggestion is to use the provided Crosstab Wizard and Visual Studio designer to create the item and set the data, and finally check the generated code in the *.designer.cs(vb) file.

You may find useful the following help articles:


If you need further help, post your report definition code and details about the used data. Feel free to open a support ticket and send us there the requested details.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
sebastian
Top achievements
Rank 1
Answers by
Hadib Ahmabi
Top achievements
Rank 1
Jorge
Top achievements
Rank 1
Stef
Telerik team
Share this question
or